-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.0.2, 1.2.0
-
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 --
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 --
- duplicates
-
JDK-4137479 Alt-key navigation does not work correctly
-
- Closed
-
-
JDK-4175820 Item Menus which have same mnemonic as their menu get invalid action events
-
- Closed
-
- relates to
-
JDK-4140857 Mnemonics not working properly for JRadioButtonMenuItem and JCheckBoxMenuItem
-
- Closed
-