JDK-6536197 : Focus transfer does not happen properly when a window is disposed
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2007-03-20
  • Updated: 2011-01-19
  • Resolved: 2007-06-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Description
This behavior is reproducable with Linux and Solaris platforms.

I've a Frame having a button, visible on screen. On clicking the button, a Window (whose owner is the Frame) is shown and on clicking a button on Window, a Dialog is shown. Now, I dispose the Dialog. I expect focus to return to the button on the Window.

With jdk 7 (b06): Focus does not reach any of the components, and KeyboardFocusManager.getFocusOwner returns null.
With mustang: Focus reaches the button on the Window when Dialog is disposed
On Windows: Focus reaches the button on the Window when Dialog is disposed

I click a button (B) on the Window to close the Window. Now, the Frame is the only window shown on screen.

With jdk 6 & 7: Focus does not reach any of the components, but KeyboardFocusManager.getFocusOwner returns B even though B is no longer visible. 
On Windows: When Window is closed, focus reaches the button on the Frame.

To reproduce the behavior, run the code below and click the 'Open Window' button on Frame

import java.awt.*;
import java.awt.event.*;

public class TopLevelFocusTest {

    private static Frame f;
    private static Window w;
    private static Dialog d;

    public static void main(String[] args) {
        f = new Frame("Frame");
        w = new Window(f);
        w.setSize(200, 200);
        w.setLocation(250, 0);
        d = new Dialog(f);
        d.setSize(200, 200);
        d.setLocation(0, 250);
        d.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent event) {
                d.dispose();
            }
        });
        d.setLayout(new FlowLayout());
        d.add(new Button("Button1"));
        d.add(new Button("Button2"));

        Button bw1 = new Button("Open Dialog");
        bw1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                d.setVisible(true);
            }
        });
        Button bw2 = new Button("Close Window");
        bw2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                w.dispose();
            }
        });
        w.setLayout(new FlowLayout());
        w.add(bw1);
        w.add(bw2);

        f.setSize(200, 200);
        Button fb = new Button("Open Window");
        fb.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                w.setVisible(true);
            }
        });
        f.setLayout(new FlowLayout());
        f.add(fb);
        f.add(new Button("Dummy Button"));
        f.setVisible(true);
    }
}

Comments
EVALUATION The reason is the same as in 6457980.
14-06-2007