开发者

Is there a simple way to know if a modal dialog is currently displayed?

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 ar开发者_如何学Goray 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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜