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

ALT-mnemonic not working for JMenu when menu and submenu have the same mnemonic

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.0.2, 1.2.0
    • client-libs
    • generic, sparc
    • solaris_2.5.1, solaris_2.6, windows_nt

      ALT-mnemonic not working for JMenu when menu and submenu have the same mnemonic.

      Steps to simulate the same,

      1. Run the application given below.
      2. Press Alt-4 - The menu does not get activated as it has a submenu with the same mnemonic - 4.
      3. Press Alt-5 - The menu gets activated as it does not have a submenu with the same mnemonic - 5.


      Note that for the first menu, it works fine anyway.

      This happens only when the menuitem is of type JMenu and is added as a submenu to a menu and the submenu and the main menu have the same mnemonic.

      -- Sample Code --
      import java.awt.*;
      import com.sun.java.swing.*;

      public class Tst extends JFrame {
      int nMenuCount = 10;
      public Tst() {
      JMenu jmenu;
      JMenuItem jmenuitem;
      JMenu jsubmenu;
      JMenuBar jmenubar = new JMenuBar();

      for(int i = 0; i < nMenuCount; i ++) {
      jmenu = new JMenu("JMenu" + i);
      jmenu.setMnemonic('0' + i);

      jmenubar.add(jmenu);

      for(int j = 0; j < 5; j ++) {
      jsubmenu = new JMenu("SubMenu1" + i + j);
      jsubmenu.setMnemonic('0' + j);

      jmenu.add(jsubmenu);

      for(int k = 0; k <= j; k ++) {
      jmenuitem = new JMenuItem("JMenuItem" + i + j + k);
      jmenuitem.setMnemonic('0' + k);

      jsubmenu.add(jmenuitem);
      }
      }
      }
      getContentPane().add(jmenubar);

      pack();
      show();
      }

      public static void main(String argv[]) {
      new Tst();
      }
      }

      -- Sample Code --

            gsaab Georges Saab
            mmadhugisunw Mukund Madhugiri (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: