JDK-6886678 : Clicking on parent JFrame's client area does not switch focus from JWindow to JFrame on Windows
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u18
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2009-09-29
  • Updated: 2011-01-19
  • Resolved: 2010-01-13
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 JDK 7
6u18 b05Fixed 7Fixed
Related Reports
Relates :  
Description
1) Created JWindow with a JFrame parent that is visible.
2) When the program runs, click on JWindow - it gets focus.
3) Now click on JFrame - it should switch focus to the JFrame -
but it does not. This works fine on the mac but does not on Windows.

Comments
SUGGESTED FIX --- old/src/solaris/classes/sun/awt/X11/XContentWindow.java 2009-10-28 16:52:34.846922000 +0300 +++ new/src/solaris/classes/sun/awt/X11/XContentWindow.java 2009-10-28 16:52:34.822648000 +0300 @@ -7,6 +7,7 @@ package sun.awt.X11; import java.awt.Component; +import java.awt.Window; import java.awt.Rectangle; import java.util.logging.*; import java.awt.Insets; @@ -125,6 +126,23 @@ } } + public void handleButtonPressRelease(XEvent xev) { + if (xev.get_type() == ButtonPress) { + Window parentWindow = (Window)parentFrame.getTarget(); + /* + * In case the decorated frame is active but not focused + * (that is an owned window is currently focused) + * it should be made a focused window. + * This is needed to focus the frame when it's clicked + * in an empty spot of its content area. See 6886678. + */ + if (parentWindow != null && parentWindow.isActive() && !parentWindow.isFocused()) { + parentFrame.requestWindowFocus(); + } + } + super.handleButtonPressRelease(xev); + } + void purgeIconifiedExposeEvents() { for (SavedExposeEvent evt : iconifiedExposeEvents) { super.handleExposeEvent(evt.target, evt.x, evt.y, evt.w, evt.h); --- old/src/windows/native/sun/windows/awt_Frame.cpp 2009-10-28 16:52:35.560161000 +0300 +++ new/src/windows/native/sun/windows/awt_Frame.cpp 2009-10-28 16:52:35.512674000 +0300 @@ -1038,9 +1038,25 @@ // EmbeddedFrame focus stuff //////////////////////////// -void AwtFrame::ActivateEmbeddedFrameOnMouseDown() + +void AwtFrame::ActivateFrameOnMouseDown() { - ActivateEmbeddedFrameHelper(AwtComponent::GetFocusedWindow()); + if (IsEmbeddedFrame()) { + ActivateEmbeddedFrameHelper(AwtComponent::GetFocusedWindow()); + } else { + /* + * In case the frame is active but not focused + * (that is an owned window is currently focused) + * it should be sent an activating message. + * This is needed to focus the frame when it's clicked + * in an empty spot of its client area. See 6886678. + */ + if (GetHWnd() == ::GetActiveWindow() && + GetHWnd() != AwtComponent::GetFocusedWindow()) + { + SynthesizeWmActivate(TRUE, AwtComponent::GetFocusedWindow()); + } + } } /* --- old/src/windows/native/sun/windows/awt_Component.cpp 2009-10-28 16:52:36.696750000 +0300 +++ new/src/windows/native/sun/windows/awt_Component.cpp 2009-10-28 16:52:36.559172000 +0300 @@ -2508,14 +2508,14 @@ MSG msg; InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y); - /* - * Activate EmbeddedFrame if applicable. It should be done - * before the MOUSE_PRESSED event (posted below) will trigger - * WM_SETFOCUS (when it's back to the native code) on the component. - */ AwtWindow *toplevel = GetContainer(); - if (toplevel && toplevel->IsEmbeddedFrame()) { - ((AwtFrame*)toplevel)->ActivateEmbeddedFrameOnMouseDown(); + if (toplevel && !toplevel->IsSimpleWindow()) { + /* + * Activate the frame if applicable. It should be done + * before the MOUSE_PRESSED event (posted below) will trigger + * WM_SETFOCUS (when it's back to the native code) on the component. + */ + ((AwtFrame*)toplevel)->ActivateFrameOnMouseDown(); } SendMouseEvent(java_awt_event_MouseEvent_MOUSE_PRESSED, now, x, y, --- old/src/windows/native/sun/windows/awt_Frame.h 2009-10-28 16:52:38.596600000 +0300 +++ new/src/windows/native/sun/windows/awt_Frame.h 2009-10-28 16:52:38.571370000 +0300 @@ -119,7 +119,7 @@ void SynthesizeWmActivate(BOOL doActivate, HWND opposite); - void ActivateEmbeddedFrameOnMouseDown(); + void ActivateFrameOnMouseDown(); BOOL ActivateEmbeddedFrameOnSetFocus(HWND hWndLostFocus); void DeactivateEmbeddedFrameOnKillFocus(HWND hWndGotFocus); BOOL ActivateEmbeddedFrameHelper(HWND oppositeToplevelHWnd);
28-10-2009

EVALUATION It works with XAWT in jdk7, but not in jdk6... So, we have to fix it for both the toolkits.
28-10-2009

EVALUATION This works with XAWT.
30-09-2009