views:

31

answers:

1

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.)

+1  A: 

(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;
}
Geoffrey Zheng