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

Multiple usage of same mnemonic in menu leads to unexpected effects

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.2.2
    • client-libs
    • None
    • sparc
    • solaris_1, solaris_2.5.1

      > > we have a 'Windows' menu with mnemonic 'W' as well as a menu item 'Window
      > > List..' with the same mnemonic.
      > > When typing Alt+W the pulldown menubar opens AND the ActionEvent is being
      > > fired.
      > > Is there any simple answer to that ?


      This is reproducible using 1.2fcs and jdk1.2.2-T.

      However in 1.3 the ActionEvent is not fired when Alt+E is pressed (expected
      result the menu is pulled down), but if you press ALT+E again the ActionEvent
      should be fired, but it is not.

      Test Case that I used is :-

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class MenuSample {
        static class MenuActionListener implements ActionListener {
          public void actionPerformed (ActionEvent e) {
            System.out.println ("Selected: " + e.getActionCommand());
          }
        }
        public static void main(String args[]) {
          ActionListener menuListener = new MenuActionListener();
          JFrame frame = new JFrame("MenuSample Example");
          JMenuBar bar = new JMenuBar();

          JMenu file = new JMenu("File");
          file.setMnemonic('F');
          bar.add(file);

          JMenuItem closeItem = new JMenuItem("Close");
          closeItem.setMnemonic('C');
          closeItem.addActionListener(menuListener);
          file.add(closeItem);

          JMenu edit = new JMenu("Edit");
          edit.setMnemonic('E');
          bar.add(edit);
       
          JMenuItem cutItem = new JMenuItem("Cut");
          cutItem.setMnemonic('C');
          cutItem.addActionListener(menuListener);
          edit.add(cutItem);

        
          JMenuItem editItem = new JMenuItem("Editlist");
          editItem.setMnemonic('E');
          editItem.addActionListener(menuListener);
          edit.add(editItem);


          frame.setJMenuBar(bar);
          frame.setSize(350, 250);
          frame.setVisible(true);
        }
      }


      adele.carrie@ireland 1999-07-02

            gsaab Georges Saab
            acarrie Adele Carrie
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: