JDK-6435408 : Frame-Dialog window hierarchy behaves weird
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2006-06-07
  • Updated: 2011-04-29
Related Reports
Relates :  
Description
This is reproducible from 1.4 onwards on all platforms.

I've two Dialogs (D1 & D2) with a Frame (F) as parent. Both the dialogs are modal. I show F first followed by D1 and D2. On clicking a button on D2, I call setVisible(false) on the frame. This hides the frame and the dialogs. Now, if I call setVisible(true) on the frame, only F and D1 is shown, D2 doesn't appear.

Run the attached testcase for reproducing the behavior. 
The testcase shows two Frames. Click the button on the frame titled 'F'. A dialog is shown. Click the button 'Open D2' on the dialog 'D1'. This shows Dialog D2. Click the 'Close F' button on D2, the frame and dialogs disappear. If clicking the 'Open F' button on the frame brings up F and D1 only, the bug is reproduced.

If the same sequence is tried out, sometimes, hiding the frame causes the parent frame to get hidden while the child Dialog still staying on the screen.
The same bug is also reproduced with the attached test (ModalVisiblityTest.java) where one of the restored windows is a modal dialog. Modal dialog is restored properly the first time but fails thereafter.

Comments
SUGGESTED FIX --- Window.java 2007-04-13 16:03:13.000000000 +0400 *************** *** 895,901 **** 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 --- 895,905 ---- for (int i = 0; i < ownedWindowList.size(); i++) { Window child = ownedWindowList.elementAt(i).get(); if ((child != null) && child.showWithParent) { ! if (child instanceof Dialog) { ! ((Dialog)child).blockingShow(false); ! } else { ! child.show(); ! } child.showWithParent = false; } // endif } // endfor --- Dialog.java 2007-04-13 16:02:54.000000000 +0400 *************** *** 1034,1039 **** --- 1034,1043 ---- */ @Deprecated public void show() { + blockingShow(false); + } + + void blockingShow(boolean blockCurrentThread) { beforeFirstShow = false; if (!isModal()) { conditionalShow(null, null); *************** *** 1080,1086 **** Iterator it = AppContext.getAppContexts().iterator(); while (it.hasNext()) { AppContext appContext = (AppContext)it.next(); ! if (appContext == showAppContext) { continue; } EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY); --- 1084,1090 ---- Iterator it = AppContext.getAppContexts().iterator(); while (it.hasNext()) { AppContext appContext = (AppContext)it.next(); ! if ((appContext == showAppContext) && blockCurrentThread) { continue; } EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY); *************** *** 1097,1102 **** --- 1101,1107 ---- modalityPushed(); try { + if (blockCurrentThread) { if (EventQueue.isDispatchThread()) { /* * dispose SequencedEvent we are dispatching on current *************** *** 1136,1141 **** --- 1141,1147 ---- } } } + } } finally { modalityPopped(); } *************** *** 1146,1152 **** Iterator it = AppContext.getAppContexts().iterator(); while (it.hasNext()) { AppContext appContext = (AppContext)it.next(); ! if (appContext == showAppContext) { continue; } EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY); --- 1152,1158 ---- Iterator it = AppContext.getAppContexts().iterator(); while (it.hasNext()) { AppContext appContext = (AppContext)it.next(); ! if ((appContext == showAppContext) && blockCurrentThread) { continue; } EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
13-04-2007

EVALUATION Reproducible at least on windows and linux platforms. I suspect the problem is in the code that shows all the owned windows when the frame becomes visible. If one of these owned windows is a modal dialog, it blocks current thread and all other owned windows are shown only after it is closed.
08-06-2006