Is there one method in AWT or Swing to either tell me if there's a modal window (or multiple) up, or to return an array of them?
I looked in Window
, Dialog
, JDialog
, SwingUtilities
, etc. but couldn't find one.
(I know I can loop through Window#getWindows
and check Dialog#isModal
.)
(This is what I know and works, though I'm not sure if it's correct to use Window#isShowing
, or if I should use something else.)
public static boolean isModalDialogShowing()
{
Window[] windows = Window.getWindows();
if( windows != null ) { // don't rely on current implementation, which at least returns [0].
for( Window w : windows ) {
if( w.isShowing() && w instanceof Dialog && ((Dialog)w).isModal() )
return true;
}
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With