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

Accelerators for JMenuItems cease to work when focus is lost

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Cannot Reproduce
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b99)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b99, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.6.9-34Elsmp i686

      A DESCRIPTION OF THE PROBLEM :
      Accelerators for JMenuItems work while the parent JFrame holds the focus, when the focus is lost once and then switched back to the parent JFrame the accelerators work no more.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the provided example. When AcceleratorTestFrame "1" appears, hit 'Ctrl+W' - a second AcceleratorTestFrame "2" appears and requests the focus. Now switch the focus back to AcceleratorTestFrame "1" (for example by closing AcceleratorTestFrame "2", or via click-to-focus). Hit 'Ctrl+W' again.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The accelerator should behave similar to the first time it was invoked: a third AcceleratorTestFrame "3" should appear. This is what happens using JDK 5.0.
      ACTUAL -
      Nothing happens - the accelerator doesn't work anymore.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import java.awt.event.ActionEvent;
      import java.awt.event.InputEvent;
      import java.awt.event.KeyEvent;
      import java.util.Date;

      import javax.swing.AbstractAction;
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.KeyStroke;

      public class AcceleratorTestFrame extends JFrame {
          static int counter = 0;
          int mycounter;
          
          public AcceleratorTestFrame() {
              super("" + ++counter);
              mycounter = counter;
              
              JMenuBar menuBar = new JMenuBar();
              getContentPane().add(menuBar, BorderLayout.NORTH);
              
              JMenu menu = new JMenu("Test Menu");
              menuBar.add(menu);
              
              JMenuItem item = new JMenuItem("Test Item");
              menu.add(item);
              
              item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK));
              item.addActionListener(new AbstractAction() {
                  public void actionPerformed(ActionEvent e) {
                      System.out.println(new Date()+": Action performed ("+mycounter+")");
                      (new AcceleratorTestFrame()).setVisible(true);
                  }
              });

              pack();
              Dimension d = getSize();
              d.width = 120;
              setSize(d);
          }

          public static void main(String[] args) {
              (new AcceleratorTestFrame()).setVisible(true);
          }
      }

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              serb Sergey Bylokhov
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: