从打开的Applet模型对话框更改浏览器选项卡时,放在后面的Applet [英] Model dialog opened from Applet is placed behind Applet when changing Browser tabs

查看:146
本文介绍了从打开的Applet模型对话框更改浏览器选项卡时,放在后面的Applet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

小程序包括以下code的:

The applet consists of following code:

public class TestApplet extends Applet {
public TestApplet() {
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            JDialog dialog = new JDialog();
            dialog.setContentPane(new JLabel("Hello"));
            dialog.setSize(new Dimension(300, 200));
            dialog.setModal(true);
            dialog.setVisible(true);
        }
    });
}}

当我打开它在Windows 7上运行的InternetExplorer它的工作原理:我改变浏览器标签,对话始终走在前面。

When I open it on InternetExplorer running on Windows 7 it works: I change browser tabs, dialog always stays in front.

当我打开它上的红帽企业Linux服务器版本6.3运行Firefox ESR 10.0.5,爪哇1.7.0_07-B10则立即进入浏览器窗口的后面,我要为了再次找到它最小化浏览器。

When I open it on Firefox ESR 10.0.5 running on Red Hat Enterprise Linux Server Release 6.3, Java 1.7.0_07-b10 then it instantly goes behind the Browser window and I have to minimize browser in order to find it again.

我有什么做的,使模态对话框总是停留在小程序?

What do I have to do to make the modal dialog always stay in front of the Applet?

更新:

更改的JDialog的创建到

Changing creation of JDialog to

JDialog dialog = new JDialog(javax.swing.SwingUtilities.getWindowAncestor(TestApplet.this));

使得没有区别。

推荐答案

最后,尝试了很多事情之后,我想通了以下解决方法:

Finally, after trying alot of things I figured out the following workaround:

public class ModalDialog extends JDialog {

    private boolean isClosing = false;

    protected synchronized boolean isClosing() {
        return isClosing;
    }


    protected synchronized void setClosing(boolean isClosing) {
        this.isClosing = isClosing;
    }

    public ModalDialog() {
        setSize(200, 300);
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

        addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent arg0) {
                if (isClosing()) {
                    System.out.println("Returned because dialog is already closing");
                    return;
                }
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        ModalDialog.this.setVisible(false);
                        ModalDialog.this.setVisible(true);
                    }
                });
            }
        });
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.out.println("Dialog is closing");
                setClosing(true);

            }
        });
    }
}

这篇关于从打开的Applet模型对话框更改浏览器选项卡时,放在后面的Applet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆