4

问题:用户从小程序开始长时间操作;显示带有进度条的 JDialog。用户打开/切换到另一个浏览器选项卡 - JDialog 仍然显示(并惹恼用户)。

当用户切换到另一个选项卡时,应该隐藏 JDialog;并在用户切换回来时再次显示。

注意:我看到有类似问题的问题,解决方案是添加 windowActivated/deactivated 侦听器。它对我不起作用,因为窗口中有多个框架,其中一个包含小程序。当用户单击另一个框架时,会强制转换 windowDeactivate 事件,但用户仍在同一选项卡中。

4

2 回答 2

5

尝试将小程序指定为对话框的所有者:

JDialog dialog = new JDialog(SwingUtilities.windowForComponent(this));

其中“this”是 JApplet。希望这会在每次父母失去焦点时激活/停用对话框。

于 2011-09-28T14:19:06.837 回答
0

解决方案:为所有帧添加监听器

<head>

    ...
    <script type="text/javascript">
        onBlur=function(event) { window.focusFlag = false; };
        onFocus=function(event){ window.focusFlag = true; };
        function createFocusListeners()
        {
            window.focusFlag = true;

            if (/*@cc_on!@*/false) { // check for Internet Explorer
                document.onfocusin = onFocus;
                document.onfocusout = onBlur;
            } else if (typeof window.addEventListener != "undefined"){
                document.getElementById('topFrame').contentWindow.addEventListener('focus',onFocus, false);
                document.getElementById('topFrame').contentWindow.addEventListener('blur',onBlur, false);
                document.getElementById('leftFrame').contentWindow.addEventListener('focus',onFocus, false);
                document.getElementById('leftFrame').contentWindow.addEventListener('blur',onBlur, false);
                document.getElementById('mainFrame').contentWindow.addEventListener('focus',onFocus, false);
                document.getElementById('mainFrame').contentWindow.addEventListener('blur',onBlur, false);
                window.addEventListener('focus',onFocus, false);
                window.addEventListener('blur',onBlur, false);
            }
        };

        //main frame is constantly reloaded, must add listener after each reload
        window.createMainFrameFocusListeners = (function () {
            if (typeof window.addEventListener != "undefined"){
        document.getElementById('mainFrame').contentWindow.addEventListener('focus',onFocus, false);
        document.getElementById('mainFrame').contentWindow.addEventListener('blur',onBlur, false);
        }
        });
    </script>
</head>


<frameset rows="32,*" cols="*" onload="createFocusListeners();">
    <frame id="topFrame" src="MenuFrame.jspx" name="topFrame" scrolling="NO" noresize="noresize"/>
    <frameset rows="*" cols="280,*">
        <frame id="leftFrame" src="TreeFrame.jspx" name="leftFrame" scrolling="NO"/>
        <frame id="mainFrame" src="ListView.jspx" name="mainFrame" scrolling="NO"/>
    </frameset>
</frameset>
于 2014-04-26T14:55:58.690 回答