-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
5.0
-
generic
-
generic
This description has been taken from 6187066. That bug described two issues, one of which belongs to Swing. Here's the relevant part of the description.
I would like to be able to open a frame without it automatically being activated and gaining focus. I can come close to this using the setFocusableWindowState method (see the supplied example code). The example throws an exception (I've included the stack below) because of what appears to be a missing null check in KeyboardManager.registerMenuBar. Commenting out the call to Frame.setJMenuBar in the example code eliminates the exception.
RESULTS:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.util.Hashtable.get(Unknown Source)
at javax.swing.KeyboardManager.registerMenuBar(Unknown Source)
at javax.swing.JMenuBar.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at javax.swing.JRootPane.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at java.awt.Window.addNotify(Unknown Source)
at java.awt.Frame.addNotify(Unknown Source)
at java.awt.Window.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at test.ShowNoActivate$1.actionPerformed(ShowNoActivate.java:26)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
CODE :
import java.awt.event.*;
import javax.swing.*;
public class ShowNoActivate {
public static void main(String[] args)
{
final JFrame frame = new JFrame("Show No Activate Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Create Inactive Frame");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JFrame inactiveFrame = new JFrame();
inactiveFrame.setJMenuBar(new JMenuBar());
inactiveFrame.setFocusableWindowState(false);
inactiveFrame.addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent we) {
frame.toFront();
we.getWindow().setFocusableWindowState(true);
we.getWindow().removeWindowListener(this);
}
});
inactiveFrame.setBounds(frame.getX() + 100, frame.getY(), 300, 300);
inactiveFrame.setVisible(true);
}
});
frame.getContentPane().add(button);
frame.pack();
frame.setVisible(true);
}
}
###@###.### 11/2/04 16:16 GMT
I would like to be able to open a frame without it automatically being activated and gaining focus. I can come close to this using the setFocusableWindowState method (see the supplied example code). The example throws an exception (I've included the stack below) because of what appears to be a missing null check in KeyboardManager.registerMenuBar. Commenting out the call to Frame.setJMenuBar in the example code eliminates the exception.
RESULTS:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.util.Hashtable.get(Unknown Source)
at javax.swing.KeyboardManager.registerMenuBar(Unknown Source)
at javax.swing.JMenuBar.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at javax.swing.JComponent.addNotify(Unknown Source)
at javax.swing.JRootPane.addNotify(Unknown Source)
at java.awt.Container.addNotify(Unknown Source)
at java.awt.Window.addNotify(Unknown Source)
at java.awt.Frame.addNotify(Unknown Source)
at java.awt.Window.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at test.ShowNoActivate$1.actionPerformed(ShowNoActivate.java:26)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
CODE :
import java.awt.event.*;
import javax.swing.*;
public class ShowNoActivate {
public static void main(String[] args)
{
final JFrame frame = new JFrame("Show No Activate Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Create Inactive Frame");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JFrame inactiveFrame = new JFrame();
inactiveFrame.setJMenuBar(new JMenuBar());
inactiveFrame.setFocusableWindowState(false);
inactiveFrame.addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent we) {
frame.toFront();
we.getWindow().setFocusableWindowState(true);
we.getWindow().removeWindowListener(this);
}
});
inactiveFrame.setBounds(frame.getX() + 100, frame.getY(), 300, 300);
inactiveFrame.setVisible(true);
}
});
frame.getContentPane().add(button);
frame.pack();
frame.setVisible(true);
}
}
###@###.### 11/2/04 16:16 GMT
- duplicates
-
JDK-6179853 REGRESSION: Making a defLAFdecorated JFrame non-focusable throws a NPE
- Closed
- relates to
-
JDK-6187066 Want to open a Frame without activating it
- Closed