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

JMenu and JMenuItem with same mnemonic still broken

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • None
    • solaris_9, 1.1.8, 1.2.2, 1.3.0
    • client-libs
    • generic, x86, sparc
    • generic, solaris_1, solaris_2.5.1, solaris_8, windows_95

    Description



      Name: skT88420 Date: 06/15/99


      When a JMenuItem Mnemonic is the same as its JMenu mnemonic, the behavior has changed, but it's still wrong.

      For example, Suppose I have a menu called "Sort" with an item called "Sort by Selection", and both had the mnemonic set to S.

      Under JDK 1.2.1, typing alt-S would bring up the menu, and invoke the item, leaving the menu up.

      Under JDK 1.2.2RC, it still invokes the item, but it dismisses the menu. So it acts like a hot key.

      This is probably covered under bug 4171437, but that bug is marked as fixed. Many of the problems that fall under that bug are in fact fixed, but this one is still a problem.
      (Review ID: 84181)
      ======================================================================

      Name: krT82822 Date: 09/14/99


      Create menu with mnemonic 'F'. In this menu put menuitem with accelerator 'F'.
      When user presses 'Alt-F', action belonged to menuitem with 'F' is done!

      Here is some code:

      import javax.swing.*;
      import java.awt.event.*;
      public class MenuBug {
          JFrame frame = new JFrame("Buggy!");

          public MenuBug() {
              JMenuBar menuBar = new JMenuBar();
              JMenu file = new JMenu("File");
              file.setMnemonic('F');
              JMenuItem fixIt = new JMenuItem("Fix It");
              fixIt.setMnemonic('F');
              fixIt.addActionListener(new Buggy());
              JMenuItem exit = new JMenuItem("Exit");
              file.add(fixIt);
              file.add(exit);
              menuBar.add(file);
              
              frame.setJMenuBar(menuBar);
              frame.setSize(100,50);
              frame.setVisible(true);
              frame.addWindowListener(new WindowAdapter() {
                      public void windowClosing(WindowEvent we) {
                          System.exit(0);
                      }
                  });
          }
          
          public static void main(String[] argv) {
              MenuBug bug = new MenuBug();
          }

          class Buggy implements ActionListener {
              public void actionPerformed(ActionEvent ae) {
                  System.err.println("BUG!!");
              }
          }
      }
      (Review ID: 95234)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              svioletsunw Scott Violet (Inactive)
              skonchad Sandeep Konchady
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: