【问题标题】:Is there a simple way to know if a modal dialog is currently displayed?有没有一种简单的方法可以知道当前是否显示了模式对话框?
【发布时间】:2010-10-06 16:05:24
【问题描述】:

AWT 或 Swing 中是否有一种方法可以告诉我是否有一个模式窗口(或多个),或者返回它们的数组?

我查看了WindowDialogJDialogSwingUtilities 等,但找不到。

(我知道我可以遍历Window#getWindows 并检查Dialog#isModal。)

【问题讨论】:

    标签: java swing modal-dialog awt


    【解决方案1】:

    (这是我所知道并有效的方法,虽然我不确定使用 Window#isShowing 是否正确,或者我是否应该使用其他东西。)

    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;
    }
    

    【讨论】:

    • 先生,你是个野兽!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-01
    • 2017-03-04
    • 2011-08-26
    • 2018-07-13
    • 2014-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多