How to hide JDialog from JApplet when user switch browser tab?

ⅰ亾dé卋堺 提交于 2019-12-01 19:49:39

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.

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!