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

Mnemonics not working properly for JRadioButtonMenuItem and JCheckBoxMenuItem

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P2 P2
    • None
    • 1.2.0
    • client-libs
    • None

      Mnemonics not working properly for JRadioButtonMenuItem and JCheckBoxMenuItem. If the menu and the radiobuttonmenuitem or checkboxmenuitem have the same mnemonic, it does not work properly.

      Steps to simulate the same,
      1. Run the application given below,
      2. JMenu0 has JMenuItem, JMenu1 has JRadioButtonMenuItem and JMenu03 has JCheckBoxMenuItem
      3. Press Alt-0 and then 1. Works fine and check output for actionevent fired.
      4. Press Alt-1 and then 2 - Instead of selecting the second item and closing the menu, the menu JMenu02 is activated.
      5. Press Alt-2 and then 1 - Instead of selecting the first item and closing the menu, the menu JMenu01 is activated.


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

      public class Tst1 extends JFrame {
      public Tst1() {
      JMenuBar jmenubar = new JMenuBar();

      int i = 0;
      JMenu jmenu = new JMenu("JMenu" + i);
      jmenu.setMnemonic('0' + i);
      for(int j = 0; j < 5; j ++) {
      JMenuItem jmenuitem = new JMenuItem("JMenuItem" + i + j);
      jmenuitem.setMnemonic('0' + j);
      jmenuitem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      System.out.println(e);
      }
      });
      jmenu.add(jmenuitem);
      }
      jmenubar.add(jmenu);


      i ++;
      jmenu = new JMenu("JMenu" + i);
      jmenu.setMnemonic('0' + i);
      for(int j = 0; j < 5; j ++) {
      JRadioButtonMenuItem jradiobuttonmenuitem = new JRadioButtonMenuItem("JRadioButtonMenuItem" + i + j);
      jradiobuttonmenuitem.setMnemonic('0' + j);
      jradiobuttonmenuitem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      System.out.println(e);
      }
      });
      jmenu.add(jradiobuttonmenuitem);
      }
      jmenubar.add(jmenu);


      i ++;
      jmenu = new JMenu("JMenu" + i);
      jmenu.setMnemonic('0' + i);
      for(int j = 0; j < 5; j ++) {
      JCheckBoxMenuItem jcheckboxmenuitem = new JCheckBoxMenuItem("JCheckBoxMenuItem" + i + j);
      jcheckboxmenuitem.setMnemonic('0' + j);
      jcheckboxmenuitem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      System.out.println(e);
      }
      });
      jmenu.add(jcheckboxmenuitem);
      }
      jmenubar.add(jmenu);

      getContentPane().add(jmenubar);

      pack();
      show();
      }

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

      -- Sample Code --

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: