Name: mt13159 Date: 10/24/2001
This bug was introduced in JDK 1.3.1_01, and I believe it is related to the fix for bug 4380809. If you minimize a window, the focused component gets a FOCUS_LOST event. If you then restore the window, the component does not get a FOCUS_GAINED event, and focus is lost. The following test case illustrates the problem. When you run it, notice that the button has a focus rectangle drawn in it. Minimize the window and restore it. Notice that the focus rectangle has disappeared. If you look at the console output, you can see that this is because no FOCUS_GAINED event was sent when you restored the window.
import javax.swing.*;
import java.awt.event.*;
public class Test extends JFrame {
public Test() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
JButton button = new JButton("Button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Button pressed!");
}
});
button.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent e) {
System.out.println("Focus lost");
}
public void focusGained(FocusEvent e) {
System.out.println("Focus gained");
}
});
getContentPane().add(button);
}
public static void main(String args[]) {
Test frame = new Test();
frame.pack();
frame.setVisible(true);
}
}
This appears to have been introduced by the fix for Sun bug 4380809. That bug clearly states that it did not reproduce in JDK 1.3. Yet for some unknown reason, Sun seems to have included the fix for that bug in JDK 1.3.1_01, causing this bug. Sun bug 4380809 does not reproduce in JDK 1.3, so a simple fix would simply be to back out the fix for bug 4380809 from JDK 1.3.1_01. This is in awt_component.cpp. Simply return the WM_ACTIVATE and WM_SETFOCUS message handling back to the way they were in JDK 1.3.1.
This bug does not reproduce in JDK 1.4, but it should be fixed in any future releases of JDK 1.3.1.
(Review ID: 134265)
======================================================================