Is there an easy way to find out if a modal dialog is displayed?

Is there any method in AWT or Swing to tell me if there is a modal window (or several) or to return an array from them?

I looked through Window , Dialog , JDialog , SwingUtilities , etc., but could not find it.

(I know that I can go through Window#getWindows and check Dialog#isModal .)

+7
java swing awt modal-dialog
source share
1 answer

(This is what I know and works, although I'm not sure if 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; } 
+10
source share

All Articles