File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Forcibly closing all open dialogs on an Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Forcibly closing all open dialogs on an Applet " Watch "Forcibly closing all open dialogs on an Applet " New topic
Author

Forcibly closing all open dialogs on an Applet

Sabhtarsha Kore
Greenhorn

Joined: Jun 22, 2005
Posts: 3
Hi All,
Had a query-- if we can forcibly close all the open dialogs on an Applet. Googled about it but did not get any easy way to do it.

Actually I want to do this because my applet can logout due to many reasons, one of which is network failure, which can occur to a background thread, in this case if a modal dialog is visible on the applet it would remain visible whereas the applet below can log itself out and start showing the login back screen. So I would like the applet to close all the visible dialogs when it logs out. (due to any reason)

It would be great even if we get a collection of all dialogs opened over an applet, we can easily call dispose on them.
Found a way to get this list, below is the pseudo code, but I am not convinced in doing it this way.

------------------------------------
Field fieldModalDialog = Dialog.class.getDeclaredField("modalDialogs");
Collection modalDialogs = (Collection) fieldModalDialog.get(dialog);
for each modalDialog in modalDialogs{modalDialog.dispose);}
------------------------------------
But again this would give us a list of modalDialogs.. I have'nt searched any thing for non-modal dialogs..

Does anyone know a way better than this?

~sabhtarsha~
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
Welcome to JavaRanch.

The applet should keep references to all the windows/dialogs that it opens; then it can just call their close() method whenever appropriate.


Ping & DNS - updated with new look and Ping home screen widget
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

Shouldn't that be setVisible(false) or dispose()?
Either way, just make sure to do it on the Event Dispatcher Thread. You can use EventQueue.invokeLater if needed.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
Oops, quite right, dispose() is what I meant.
Sabhtarsha Kore
Greenhorn

Joined: Jun 22, 2005
Posts: 3
Well, thanks guys for your replies.
I wanted some other way to get the list of open dialogs on a applet or a window, is'nt there any method or some way we can retrieve it. I am sure they (or looking at the source code they _do_) keep the list of open dialogs. Its just that they have'nt shared it through an API.

Any ways.. thanks for trying, as the dialogs in my application are used with a wrapper on JDialog its easy for me to maintain this list and flush the open dialogs at any time. But if this would not have been the case then it would have been difficult ....

Thanks,
~sabhtarsha~

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

Since Java 6, java.awt.Window has a method called getWindows() which
Returns an array of all Windows, both owned and ownerless, created by this application. If called from an applet, the array includes only the Windows accessible by that applet.

Warning: this method may return system created windows, such as a print dialog. Applications should not assume the existence of these dialogs, nor should an application assume anything about these dialogs such as component positions, LayoutManagers or serialization.

You would need to iterate over it and filter out the dialogs:
Sabhtarsha Kore
Greenhorn

Joined: Jun 22, 2005
Posts: 3
Thanks Rob
and Thanks to 1.6
It works.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Forcibly closing all open dialogs on an Applet
 
Similar Threads
All Netscape/Mozilla windows blocking with Modal Dialogs
Applet dialog not getting focus when coming back to screen using Alt-Tab
double dialogs
Correct behaviour when launching a new window and getting rid of the first window
Modal dialog box and request focus