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

KeyBindings will fail when RunnableCanvas gets focus

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1, 1.2.0
    • client-libs
    • None
    • x86, sparc
    • solaris_2.6, windows_nt

      SystemEventQueueUtilities.RunnableCanvas is getting focus, causing keyboard bindings to now work.
      Try running the following program and selecting test->test from the menu. This will create a new InternalFrame. On the console it will print out the current focus owner, which becomes the RunnableCanvas. Since the RunnableCanvas has focus the binding control-n will not work. If you click on the button the button will get focus and control-n will work again. Closing the internal frame causes focus to go back to the RunnableCanvas, and bindings won't work again.
      import com.sun.java.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class IFTest {
          Runnable focusRunnable;

          public IFTest() {
      JMenuBar mb = new JMenuBar();
      JMenu menu = new JMenu("Test");
      JMenuItem newMI = new JMenuItem("test");
      final JFrame frame = new JFrame("TEST");
      final JDesktopPane dp = new JDesktopPane();

      mb.add(menu);
      menu.add(newMI);
      frame.setJMenuBar(mb);
      dp.setPreferredSize(new Dimension(400, 400));
      newMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
      InputEvent.CTRL_MASK));
      focusRunnable = new Runnable() {
      public void run() {
      System.out.println("Focus Owner: " + frame.getFocusOwner());
      }
      };
      newMI.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ae) {
      JInternalFrame jif = new JInternalFrame("IF");
      JTextField tf = new JTextField("HI");

      jif.getContentPane().add(new JButton("HI"));
      jif.setBounds(10, 10, 200, 200);
      jif.setClosable(true);
      dp.add(jif, 5);
      System.out.println("NEW");
      SwingUtilities.invokeLater(focusRunnable);
      }
      });

      frame.getContentPane().add(dp, BorderLayout.CENTER);
      frame.pack();
      frame.show();
      SwingUtilities.invokeLater(focusRunnable);
          }

          public static void main(String[] args) {
      new IFTest();
          }
      }
      It should be noted this only happens on Solaris, NT doesn't seem to have this behavior.

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: