JDK-6391763 : REG: Window not gaining focus even after the parent dialog is made visible, WinXP
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-02-28
  • Updated: 2007-10-16
  • Resolved: 2006-04-05
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 b79Fixed
Related Reports
Relates :  
Description
I am creating a Frame, Dialog and a Window. Frame is the parent of the dialog and dialog is the parent of the window. Initially I am making the frame and the window visible. Window is not gaining focus when clicked since the dialog is not showing. On clicking a button in the frame, I am opening the modal dialog. Modal dialog does not block the window since the window is it's child. Now I am clicking on the window, expecting it to gain focus. But the window is not gaining focus even after the dialog is shown. But when I hide and shown the dialog again, the window gains focus.

This is reproducible only on WinXP and not on XToolkit. This is reproducible on Mustang-b73 but not on Tiger-FCS. Hence this is a regression in Mustang.

I have attached a sample test. Execute the sample test. You would see few windows on the screen. Try clicking on the window located to the left of 'Blocked Frame'. It will not gain focus. Now click on 'Open Dialog' button. A modal dialog will be shown. Now click on the 'Dummy' button on the same window. If it does not gain focus, the bug is reproduced (Test can be run as an application as well as Applet).

Comments
SUGGESTED FIX --- Window.java 2006-03-07 19:10:46.000000000 +0300 *** 705,756 **** * @deprecated As of JDK version 1.5, replaced by * {@link setVisible(boolean) setVisible(boolean)}. */ @Deprecated public void show() { ! if (peer == null) { ! addNotify(); ! } ! validate(); isInShow = true; ! if (visible) { ! toFront(); ! } else { beforeFirstShow = false; if (beforeFirstWindowShown.getAndSet(false)) { SunToolkit.closeSplashScreen(); } ! Dialog.checkShouldBeBlocked(this); ! super.show(); locationByPlatform = false; ! boolean isFrameOrDialog = (this instanceof Frame || ! this instanceof Dialog); ! for (int i = 0; i < ownedWindowList.size(); i++) { Window child = ownedWindowList.elementAt(i).get(); if ((child != null) && child.showWithParent) { child.show(); child.showWithParent = false; } // endif - if (isFrameOrDialog && (child != null)) { - updateChildFocusableWindowState(child); - } } // endfor if (!isModalBlocked()) { updateChildrenBlocking(); } ! } isInShow = false; ! // If first time shown, generate WindowOpened event if ((state & OPENED) == 0) { postWindowEvent(WindowEvent.WINDOW_OPENED); state |= OPENED; } } ! static private void updateChildFocusableWindowState(Window w) { if (w.isShowing()) { ((WindowPeer)w.getPeer()).updateFocusableWindowState(); } for (int i = 0; i < w.ownedWindowList.size(); i++) { Window child = w.ownedWindowList.elementAt(i).get(); --- 705,754 ---- * @deprecated As of JDK version 1.5, replaced by * {@link setVisible(boolean) setVisible(boolean)}. */ @Deprecated public void show() { ! if (peer == null) { ! addNotify(); ! } ! validate(); isInShow = true; ! if (visible) { ! toFront(); ! } else { beforeFirstShow = false; if (beforeFirstWindowShown.getAndSet(false)) { SunToolkit.closeSplashScreen(); } ! Dialog.checkShouldBeBlocked(this); ! super.show(); locationByPlatform = false; ! for (int i = 0; i < ownedWindowList.size(); i++) { Window child = ownedWindowList.elementAt(i).get(); if ((child != null) && child.showWithParent) { child.show(); child.showWithParent = false; } // endif } // endfor if (!isModalBlocked()) { updateChildrenBlocking(); } ! if (this instanceof Frame || this instanceof Dialog) { ! updateChildFocusableWindowState(this); ! } ! } isInShow = false; ! // If first time shown, generate WindowOpened event if ((state & OPENED) == 0) { postWindowEvent(WindowEvent.WINDOW_OPENED); state |= OPENED; } } ! static void updateChildFocusableWindowState(Window w) { if (w.isShowing()) { ((WindowPeer)w.getPeer()).updateFocusableWindowState(); } for (int i = 0; i < w.ownedWindowList.size(); i++) { Window child = w.ownedWindowList.elementAt(i).get(); --- Dialog.java 2006-03-06 20:13:14.000000000 +0300 *** 920,933 **** if ((child != null) && child.showWithParent) { child.show(); child.showWithParent = false; } // endif } // endfor ! createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, ! this, parent, ! HierarchyEvent.SHOWING_CHANGED, Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); if (componentListener != null || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) { ComponentEvent e = --- 920,934 ---- if ((child != null) && child.showWithParent) { child.show(); child.showWithParent = false; } // endif } // endfor + Window.updateChildFocusableWindowState(this); ! createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, ! this, parent, ! HierarchyEvent.SHOWING_CHANGED, Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); if (componentListener != null || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) { ComponentEvent e = --- WWindowPeer.java 2006-03-06 17:46:28.000000000 +0300 *** 109,119 **** native void createAwtWindow(WComponentPeer parent); void create(WComponentPeer parent) { createAwtWindow(parent); } ! public void show() { updateFocusableWindowState(); boolean alwaysOnTop = ((Window)target).isAlwaysOnTop(); --- 109,124 ---- native void createAwtWindow(WComponentPeer parent); void create(WComponentPeer parent) { createAwtWindow(parent); } ! ! // should be overriden in WDialogPeer ! protected void realShow() { ! super.show(); ! } ! public void show() { updateFocusableWindowState(); boolean alwaysOnTop = ((Window)target).isAlwaysOnTop(); *** 125,135 **** // super.displayChanged() in WWindowPeer.displayChanged() regardless of whether // GraphicsDevice was really changed, or not. So we need to track it here. updateGC(); resetTargetGC(); ! super.show(); updateMinimumSize(); if (((Window)target).isAlwaysOnTopSupported() && alwaysOnTop) { setAlwaysOnTop(alwaysOnTop); } --- 130,140 ---- // super.displayChanged() in WWindowPeer.displayChanged() regardless of whether // GraphicsDevice was really changed, or not. So we need to track it here. updateGC(); resetTargetGC(); ! realShow(); updateMinimumSize(); if (((Window)target).isAlwaysOnTopSupported() && alwaysOnTop) { setAlwaysOnTop(alwaysOnTop); } --- WDialogPeer.java 2006-03-07 19:12:34.000000000 +0300 *** 51,75 **** setTitle(target.getTitle()); } setResizable(target.isResizable()); } ! public void show() { Dialog dlg = (Dialog)target; if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) { - updateFocusableWindowState(); - - boolean alwaysOnTop = dlg.isAlwaysOnTop(); - - updateGC(); - resetTargetGC(); showModal(); - if (dlg.isAlwaysOnTopSupported() && alwaysOnTop) { - setAlwaysOnTop(alwaysOnTop); - } } else { ! super.show(); } } public void hide() { Dialog dlg = (Dialog)target; --- 51,66 ---- setTitle(target.getTitle()); } setResizable(target.isResizable()); } ! protected void realShow() { Dialog dlg = (Dialog)target; if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) { showModal(); } else { ! super.realShow(); } } public void hide() { Dialog dlg = (Dialog)target;
15-03-2006

EVALUATION in fact we do have necessary code in Window.show(), but do not have it in Dialog.show(). I think we should add it in Dialog.showConditional() since this method is called for both modal and modeless dialogs.
06-03-2006

EVALUATION the problem is that we do not update focusbale state of native object when we show parent. I think, we need to call WWindowPeer.updateFocusableWindowState() on all childs of toplevel when we show it.
01-03-2006