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

REGRESSION: MenuItem Mnemonic KeyEvent passed to JDialog Textfield

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      A DESCRIPTION OF THE REGRESSION :
      A JFrame has a JMenuItem (e.g. 'Project') under a JMenu (e.g. 'File'). The menu item has a mnemonic (e.g. 'p'). Upon selection, the menu item opens a JDialog containing a JTextfield.

      When selecting the JMenuItem via the mnemonic, the Key_Pressed KeyEvent is consumed but subsequent Key_Typed and Key_Released KeyEvents are passed to the dialog's textfield, i.e. a 'p' appears in the textfield.

      REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
      When the following code is running, if you type "Alt-f", then "p", the dialog pops up with a 'p' in the textfield. If you click through the menu or change the JDialog to a JFrame, it acts fine (i.e. the textfield is empty).

      Sample Program:

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.KeyEvent;
       
      import javax.swing.JDialog;
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.JTextField;
       
      public class DemoCode extends JDialog {

      public DemoCode(JFrame owner) {
      super(owner,true);
      this.add(new JTextField(15));
      this.pack();
      this.setVisible(true);
      }
       
      public static void main(String[] args) {
      final JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      JMenuBar menuBar = new JMenuBar();
      JMenu fileMenu = new JMenu("File");
      fileMenu.setMnemonic(KeyEvent.VK_F);
      JMenuItem projectMenuItem = new JMenuItem("Project", KeyEvent.VK_P);

      projectMenuItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      new DemoCode(frame);
      }
      });

      fileMenu.add(projectMenuItem);
      menuBar.add(fileMenu);
      frame.setJMenuBar(menuBar);

      frame.pack();
      frame.setVisible(true);
      }
      }

      RELEASE LAST WORKED:
      5.0 Update 6

      RELEASE TEST FAILS:
      mustang-b72

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When selecting the menuitem through the mnemonic, the JDialog should pop up with an empty textfield.
      ACTUAL -
      Instead, selecting the menuitem through the mnemonic pops up the JDialog with the mnemonic entered in the textfield.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ant Anton Tarasov
              Reporter:
              ttzhang Tao Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: