JDK-4519058 : No FOCUS_GAINED event sent when restoring minimized window
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-10-25
  • Updated: 2002-06-04
  • Resolved: 2002-06-04
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
EVALUATION Fix for Merlin ###@###.### 2001-10-24 Not reproducable in Merlin. ###@###.### 2001-10-25 The fix introduced in 1.3.1_01 is for bug 4449624 that is similar to bug 4380809. The fix is necessary for some awt component focus problem and should not be backed out. We are going to address the swing focus issue in the next update release. ###@###.### 2001-11-15
15-11-2001