FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Calling setEnabled(false) on a button in the actionPerformed handler of the same button causes the window the button is in to be reactivated, if the user has activated another window in between the click and the setEnabled-call.
This used to work differently on JRE 1.3.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Start the attached Test program.
2. Click on the upper button inside window A
3. Quickly click on window B to activate it and to bring it to front
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After the 3 s delay, the upper button inside window A should be disabled
ACTUAL -
After the 3 s delay, the upper button inside window A is disabled and window A is brought to front.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
public class Test implements ActionListener {
static Button button1 = new Button("Click me and then quickly activate the other window");
public void actionPerformed(ActionEvent e) {
System.out.println("Sleep");
try { Thread.sleep(3000); } catch(InterruptedException ex) { }
System.out.println("Wake");
button1.setEnabled(!button1.isEnabled());
//button1.setEnabled(!button1.isEnabled());
}
public static void main(String[] args) {
Frame a = new Frame("Window A");
a.setBounds(0,100,200,200);
Frame b = new Frame("Window B");
b.setBounds(150,100,200,200);
button1.addActionListener(new Test());
a.setLayout(new BorderLayout());
a.add(button1, BorderLayout.NORTH);
a.add(new Button("Dummy"), BorderLayout.SOUTH);
a.show();
b.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Avoiding long-running operations inside the AWT event dispatching thread minimizes the window of opportunity for the problem to appear. A complete workaround is not known.