-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b11
-
generic
-
generic
-
Verified
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
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
- duplicates
-
JDK-6189501 NullPointerException in KeyboardManager.registerMenuBar()
-
- Closed
-