当用户切换浏览器选项卡时,如何从 JApplet 中隐藏 JDialog?

发布于 2024-12-07 04:01:36 字数 271 浏览 1 评论 0原文

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

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

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

Problem: user starts long operation from applet; JDialog with progress bar is displayed. User open/switch to another browser tab - JDialog is still displayed (and annoys user).

JDialog should be hidden when user switch to another tab; and displayed again, when user switch back.

Note: I saw question with similar problem, where solution was add windowActivated/deactivated listener. It doesn't work for me, because there are multiple frames in window, and one of them contains applet. When user clicks on another frame, windowDeactivate event is casted, but user still in the same tab.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我乃一代侩神 2024-12-14 04:01:36

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

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

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

Try specifying the applet as the owner of the dialog:

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

where "this" is the JApplet. Hopefully this will activate/deactive the dialog every time the parent loses focus.

单挑你×的.吻 2024-12-14 04:01:36

解决方案:给所有框架添加监听器

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

Solution: add listeners to all frames

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文