Name: jk109818 Date: 01/10/2003
FULL PRODUCT VERSION :
java version "1.4.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_02-b02)
Java HotSpot(TM) Client VM (build 1.4.0_02-b02, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195] SP3
A DESCRIPTION OF THE PROBLEM :
If a button has focus and a menu selection disables the
action associated with it then the button does not transfer
focus to another button.
This might be related to bug 4685768
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the example program given.
2. Choose the menu option to Disable
3. Focus locks on Message button but it is greyed out
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// FocusTest.java
import javax.swing.*;
import java.awt.event.*;
import java.awt.FlowLayout;
public class FocusTest extends JFrame {
public static void main(String [] args) {
new FocusTest().show();
}
Action action1,action2;
public FocusTest() {
getContentPane().setLayout(new FlowLayout());
action1 = new MessageAction();
action2 = new DisableAction();
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add(new JButton(action1));
getContentPane().add(new JButton(action2));
JMenu menu = new JMenu("File");
menu.setMnemonic('F');
menu.add(new JMenuItem(action1));
menu.add(new JMenuItem(action2));
setJMenuBar(new JMenuBar());
getJMenuBar().add(menu);
pack();
}
class DisableAction extends AbstractAction {
DisableAction() {
super("Disable");
putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke("alt D"));
}
public void actionPerformed(ActionEvent evt) {
action1.setEnabled(false);
}
}
class MessageAction extends AbstractAction {
MessageAction() {
super("Message");
}
public void actionPerformed(ActionEvent evt) {
JOptionPane.showMessageDialog(null,"Hello");
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Move the focus programatically before disabling the action
(Review ID: 179389)
======================================================================