-
Bug
-
Resolution: Cannot Reproduce
-
P2
-
None
-
1.2.0
-
None
-
sparc
-
solaris_2.6
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 --
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 --
- relates to
-
JDK-4140657 ALT-mnemonic not working for JMenu when menu and submenu have the same mnemonic
-
- Closed
-