Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I get the number of visible windows of my app?

Or more exact:

I need to know on a window close event, if any other window is still visible.

If not, System.exit(0) would be called.

like image 751
java.is.for.desktop.indeed Avatar asked Nov 22 '25 04:11

java.is.for.desktop.indeed


2 Answers

1) I need to know on a window close event

there are WindowConstants and WindowEvent

2) if any other window is still visible.

you can get number of Top-Level Containers by using Window[] wins = Window.getWindows(); for testing their visibility or by adding WindowStateListener

some important notice here

like image 153
mKorbel Avatar answered Nov 24 '25 16:11

mKorbel


Try

if(Frame.getFrames().length == 0) {
    // work here.
}

(Frame is java.awt.Frame, that is the parent of JFrame, so you will capture them, too).

like image 44
marc Avatar answered Nov 24 '25 18:11

marc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!