haz hazzz haz hazzz - 1 year ago 103
Java Question

Close all Java child windows

In Java Swing is there a way to find and close all

objects currently being displayed?

I have a large application and there are multiple parts that can call to display a dialog but from one single point I want to be able to detect and close it.

Answer Source

Keep a reference to each of the dialogs (perhaps in a collection). When needed, iterate the collection and call dialog.setVisible(false).

As suggested by @mKorbel, you can also use:

Window[] windows = Window.getWindows();

You'd just need to check for the 'parent' window when iterating the array and closing things.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download