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

Want to open a Frame without activating it

XMLWordPrintable

    • b14
    • generic, x86
    • generic, windows_xp
    • Verified

        A DESCRIPTION OF THE REQUEST :
        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. In any case this seems to be stretching the intended use of setFocusableWindowState. Perhaps an explicit call along the lines of "showWithoutActivating" could be added.

        JUSTIFICATION :
        This capability would allow our application to maintain focus in a debugger window, even when user actions in that window (such as single stepping) cause other frames to open

        ACTUAL -
        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)

        CUSTOMER SUBMITTED WORKAROUND :
        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);
            }
        }
        ###@###.### 10/29/04 21:42 GMT

              ant Anton Tarasov (Inactive)
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: