-
Bug
-
Resolution: Fixed
-
P3
-
1.4.1
-
02
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2108026 | 1.4.2 | Alexander Zuev | P3 | Resolved | Fixed | mantis |
Name: ks84122 Date: 05/28/2002
Incomplete fix for bug id 4227593. Dynamically built menus using mnemonics cannot be fired from the keyboard when they have submenus. The same workaround as for the original bug works. Note that when running the program below, Alt-F displays the File menu, but typing T does not cause the submenu to appear. However, submenu appears correctly using the mouse. When the applyFix() line is uncommented, the submenu does appear using the mnemonics as well.
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class TestFrame extends JFrame {
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Edit");
JMenu helpMenu = new JMenu("Help");
public TestFrame() {
fileMenu.setMnemonic('F');
fileMenu.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent e) {
System.out.println("File.menuSelected");
fileMenu.add(new JMenuItem("One", 'O'));
final JMenu twoMenu = new JMenu("Two");
/*
applyFix(twoMenu);
*/
twoMenu.setMnemonic('t');
twoMenu.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent e) {
System.out.println("FileTwo.menuSelected");
twoMenu.add(new JMenuItem("Item", 'i'));
twoMenu.add(new JMenuItem("Another Item", 'a'));
}
public void menuDeselected(MenuEvent e) {
System.out.println("FileTwo.menuDeselected");
twoMenu.removeAll();
}
public void menuCanceled(MenuEvent e) {
System.out.println("FileTwow.menuCanceled");
twoMenu.removeAll();
}
});
fileMenu.add(twoMenu);
fileMenu.add(new JMenuItem("Three", 'r'));
}
public void menuDeselected(MenuEvent e) {
System.out.println("File.menuDeselected");
fileMenu.removeAll();
}
public void menuCanceled(MenuEvent e) {
System.out.println("File.menuCanceled");
fileMenu.removeAll();
}
});
editMenu.setMnemonic('E');
editMenu.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent e) {
System.out.println("Edit.menuSelected");
editMenu.add(new JMenuItem("One", 'O'));
editMenu.add(new JMenuItem("Two", 'w'));
editMenu.add(new JMenuItem("Three", 'r'));
}
public void menuDeselected(MenuEvent e) {
System.out.println("Edit.menuDeselected");
editMenu.removeAll();
}
public void menuCanceled(MenuEvent e) {
System.out.println("Edit.menuCanceled");
editMenu.removeAll();
}
});
helpMenu.setMnemonic('H');
helpMenu.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent e) {
System.out.println("Help.menuSelected");
helpMenu.add(new JMenuItem("One", 'O'));
helpMenu.add(new JMenuItem("Two", 'w'));
helpMenu.add(new JMenuItem("Three", 'r'));
}
public void menuDeselected(MenuEvent e) {
System.out.println("Help.menuDeselected");
helpMenu.removeAll();
}
public void menuCanceled(MenuEvent e) {
System.out.println("Help.menuCanceled");
helpMenu.removeAll();
}
});
setJMenuBar(menuBar);
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(helpMenu);
}
public void applyFix(JMenu m) {
JMenuItem zero = m.add(new JMenuItem("Zero", 'Z') {
public Dimension getPreferredSize() {
if (!isVisible()) {
return new Dimension(0,0);
}
return super.getPreferredSize();
}
});
zero.setVisible(false);
}
public static void main(String[] args) {
TestFrame tf = new TestFrame();
tf.setBounds(100, 100, 500, 500);
tf.show();
}
}
(Review ID: 146563)
======================================================================
- backported by
-
JDK-2108026 JMenu: MenuListener.menuSelected() event fired too late when using mnemonics
-
- Resolved
-