-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0
-
beta
-
generic
-
generic
Name: rmT116609 Date: 11/22/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Classic VM (build 1.3.0-C, native threads, nojit)
Use the following code demonstrates the problem.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mnemonic implements ActionListener {
protected int clickCount;
protected JMenuItem menuitem;
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src instanceof JMenuItem) {
clickCount++;
System.out.println("Click count = " + clickCount);
} else if (src instanceof JButton) {
menuitem.setAccelerator(KeyStroke.getKeyStroke("F6"));
}
}
public static void main(String args[]) {
JFrame win = new JFrame("mnemonic test");
Container pane = win.getContentPane();
JButton button = new JButton("change shortcut");
mnemonic me = new mnemonic();
button.addActionListener(me);
pane.add(button);
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("menu");
me.menuitem = new JMenuItem("menu item");
me.menuitem.addActionListener(me);
menu.add(me.menuitem);
menubar.add(menu);
me.menuitem.setAccelerator(KeyStroke.getKeyStroke("F5"));
win.setJMenuBar(menubar);
win.setSize(200, 200);
win.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
win.show();
}
}
When first run, the menu item shortcut is F5. But after the button is pressed
and the shortcut is changed to F6, the F5 key still invokes the menu item. This
is not what I would expect. I would expect the F5 key to no longer active the
menu item. Only F6 should work after setAccelerator() has been called the second
time.
(Review ID: 112692)
======================================================================