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

REGRESSION: Making a defLAFdecorated JFrame non-focusable throws a NPE

    Details

    • Subcomponent:
    • Resolved In Build:
      b11
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      I am calling JFrame.setDefaultLookAndFeelDecorated(true) and creating a JFrame. After that, I am calling jframe.setFocusableWindowState(false). When the app is executed, a NullPointerException is thrown on all platforms in Tiger/Mustang. This works fine on 1.4.2.

      Here is the NPE:
      Exception in thread "main" java.lang.NullPointerException
       at java.util.Hashtable.get(Hashtable.java:336)
       at javax.swing.KeyboardManager.registerMenuBar(KeyboardManager.java:263)
       at javax.swing.JMenuBar.addNotify(JMenuBar.java:679)
       at java.awt.Container.addNotify(Container.java:2500)
       at javax.swing.JComponent.addNotify(JComponent.java:4576)
       at javax.swing.plaf.metal.MetalTitlePane.addNotify(MetalTitlePane.java:223)
       at java.awt.Container.addNotify(Container.java:2500)
       at javax.swing.JComponent.addNotify(JComponent.java:4576)
       at java.awt.Container.addNotify(Container.java:2500)
       at javax.swing.JComponent.addNotify(JComponent.java:4576)
       at javax.swing.JRootPane.addNotify(JRootPane.java:681)
       at java.awt.Container.addNotify(Container.java:2500)
       at java.awt.Window.addNotify(Window.java:458)
       at java.awt.Frame.addNotify(Frame.java:501)
       at java.awt.Window.show(Window.java:505)
       at java.awt.Component.show(Component.java:1300)
       at java.awt.Component.setVisible(Component.java:1253)
       at JFrameDecorationTest.main(JFrameDecorationTest.java:13)

      When I looked into the code more closely, the following code in the KeyboardManager.java creates the problem:

           private static Container getTopAncestor(JComponent c) {
              for(Container p = c.getParent(); p != null; p = p.getParent()) {
                  if (p instanceof Window && ((Window)p).isFocusableWindow() ||
                      p instanceof Applet || p instanceof JInternalFrame) {

                      return p;
          }
              }
              return null;
           }

      Since none of the windows are focusable here, this method returns null. 'isFocusableWindow()' check is not there in 1.4.2.

      To reproduce the bug, run the test given in the comments section. You would see the above exception on the console.
      ###@###.### 10/15/04 15:12 GMT

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                peterz Peter Zhelezniakov (Inactive)
                Reporter:
                pmohansunw Praveen Mohan (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: