JDK-4810575 : Frame does not receives focus after closing of the owned window
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-01-30
  • Updated: 2005-12-01
  • Resolved: 2005-09-17
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 6
6 b53Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Name: azR10139			Date: 01/30/2003



Run the testcase.
Press button "Press to show"
In popped window press with mouse button "Press to hide"
Note, that the frame named "test frame" does not get focus. The only 
way to get focus to the frame is to switch to another window 
and back to frame.

Seeng the debug output we can say that focus was not transferred from the
hidden window.

--- WinTest.java
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;

public class WinTest {

    public static class MyChangeListener implements PropertyChangeListener {
        public void propertyChange(PropertyChangeEvent evt) {
            Object oldF = evt.getOldValue();
            Object newF = evt.getNewValue();
            System.out.println("window focus changed from: "+oldF);
            System.out.println("window focus changed to: "+newF);
        }
    }

    public static class MyActionListener implements ActionListener {
        public boolean hideIt;
        public Window toHide;
        MyActionListener(Window w, boolean b) {
            this.toHide = w;
            this.hideIt = b;
        }

        public void actionPerformed(ActionEvent e) {
            if(hideIt) {
                toHide.dispose();
            } else {
                toHide.setLocation(200, 200);
                toHide.setVisible(true);
            }
        }
    }

    public static void main(String args[]) {

        KeyboardFocusManager mgr = 
            KeyboardFocusManager.getCurrentKeyboardFocusManager();
        mgr.addPropertyChangeListener("focusedWindow", 
                                      new MyChangeListener());

        Frame w1 = new Frame("test frame");
        Window w2 = new Window(w1);
        Button b1 = new Button("Press to show");
        b1.addActionListener(new MyActionListener(w2, false));
        Button b2 = new Button("Press to hide");
        b2.addActionListener(new MyActionListener(w2, true));
        w1.add(b1);
        w1.setLocation(100, 100);
        w1.setSize(50, 50);
        w1.show();
        w2.add(b2);
        w2.setLocation(200, 200);
        w2.setSize(80, 80);
    }
}
------------------
======================================================================

Comments
SUGGESTED FIX *** /net/aquila/export/dc158259/Mustang//webrev/src/windows/native/sun/windows/awt_Window.cpp- 2005-08-25 18:24:06.000000000 +0400 --- /net/aquila/export/dc158259/Mustang//webrev/src/windows/native/sun/windows/awt_Window.cpp 2005-08-25 18:24:06.000000000 +0400 *************** *** 928,933 **** --- 928,947 ---- MsgRouting AwtWindow::WmShowWindow(BOOL show, UINT status) { + // Fixed 4810575: Owner does not receives focus after closing of the owned window + // If the window is disposed the WM_ACTIVATE message isn't sent to the window/frame + // That's why the focus is kept on the disposed window + HWND hwndSelf = GetHWnd(); + HWND hwndParent = ::GetParent(hwndSelf); + HWND hwndActive = ::GetActiveWindow(); + HWND hwndOwner = m_owningFrameDialog ? m_owningFrameDialog->GetHWnd() : GetHWnd(); + + if (!show && hwndSelf == sm_focusedWindow && hwndParent != NULL && + hwndSelf != hwndParent && hwndOwner == hwndActive) + { + ::PostMessage(hwndParent, WM_ACTIVATE, (WPARAM)WA_ACTIVE, (LPARAM)hwndSelf); + } + //Fixed 4842599: REGRESSION: JPopupMenu not Hidden Properly After Iconified and Deiconified if (show && (status == SW_PARENTOPENING)) { if (!IsVisible()) { *** (#1 of 1): [ UNSAVED ] ###@###.###
2005-08-29

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
2004-09-22

EVALUATION Name: rpR10076 Date: 02/05/2003 As far as I can see, there's no code that would, on hide or disposal of the Window, make its parent the focused Window. This looks like a bug, such code should be added. ###@###.### 10/6/04 12:27 GMT If the window is disposed the WM_ACTIVATE message isn't sent to any window. That's why the focus is kept on the disposed window. It's reasonable to send the WM_ACTIVATE message to the owner if the window is disposed.
2004-09-22

WORK AROUND Name: azR10139 Date: 01/30/2003 Call requestFocus() for any component in the Frame returns focus to the frame. ======================================================================
2004-09-22