haz hazzz haz hazzz - 2 months ago 5x
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.


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.