Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4259274

Focus problem with two JFrames

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.2
    • client-libs



      Name: skT88420 Date: 08/03/99


      The problem is that if you programatically setVisible(false) on a JFrame on Win32, the focus is lost, ie. nothing has focus. Perhaps this is the desired behavior but I doubt it since this isn't what happens on Solaris. Moreover, once the focus is lost in this manner, if you press TAB without clicking on the visible frame, you get a NullPointerException.

      Steps to reproduce the problem:
      1. Run the code below.
      2. Notice that the visible frame does not have focus.
      3. Press TAB and get the following exception:

      java.lang.NullPointerException:
      at javax.swing.DefaultFocusManager.childrenTabOrder(DefaultFocusManager.java:347)
      at javax.swing.DefaultFocusManager.tabOrderNextComponent(DefaultFocusManager.java:296)
      at javax.swing.DefaultFocusManager.getComponentAfter(DefaultFocusManager.java:253)
      at javax.swing.DefaultFocusManager.getNextComponent(DefaultFocusManager.java:184)
      at javax.swing.DefaultFocusManager.getFocusableComponentAfter(DefaultFocusManager.java:158)
      at javax.swing.DefaultFocusManager.focusNextComponent(DefaultFocusManager.java:90)
      at javax.swing.DefaultFocusManager.processKeyEvent(DefaultFocusManager.java:75)
      at javax.swing.JComponent.processKeyEvent(JComponent.java:1527)
      at java.awt.Component.processEvent(Component.java:3008)
      at java.awt.Container.processEvent(Container.java:990)
      at java.awt.Component.dispatchEventImpl(Component.java:2394)
      at java.awt.Container.dispatchEventImpl(Container.java:1035)
      at java.awt.Component.dispatchEvent(Component.java:2307)
      at java.awt.LightweightDispatcher.processKeyEvent(Container.java:1766)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1740)
      at java.awt.Container.dispatchEventImpl(Container.java:1022)
      at java.awt.Window.dispatchEventImpl(Window.java:749)
      at java.awt.Component.dispatchEvent(Component.java:2307)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:287)
      at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:101)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:92)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:83)

      -------------------- CODE BELOW -----------------------

      import javax.swing.*;

      public class FocusTest {

          public static void main(String[] args) {
      final JFrame frame1 = new JFrame("Test 1");
      final JFrame frame2 = new JFrame("Test 2");
      frame1.setSize(200,200);
      frame1.show();

      SwingUtilities.invokeLater(new Runnable() {
      public void run() {
      frame2.setBounds(200,200,200,200);
      frame2.show();
      frame2.setVisible(false);
      }
      });
          }
          
      }

      ----------------------------------------------------

      This is exhibited on WinNT 4.0 Service Pack 5 and on Win98.

      The java version is JDK 1.2.2-W
      (Review ID: 93404)
      ======================================================================

            hgajewsksunw Hania Gajewska (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: