如何在Java applet中打开模式对话框? [英] How to open a modal dialog in Java applet?

查看:86
本文介绍了如何在Java applet中打开模式对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Applet 前面显示模式对话框.

I'm trying to display a modal dialog in front of an Applet.

我当前的解决方案像这样提取根帧:

My current solution fetches the root frame like so:

Frame getMyParent() {
    Container parent = getParent();
    while (!(parent instanceof Frame)) {
        parent = ((Component)parent).getParent();
    }
    return (Frame)parent;
}

并创建如下对话框:

public OptionsDialog(MainApplet applet, boolean modal) {
    super(applet.getMyParent(), "options", modal);
    // ....

尽管模式行为正常,但通常会在框架下方中显示模式对话框.

However often this shows the modal dialog below the frame, though the modal behaviour works correctly.

如何解决?

理想情况下,这应该适用于Java 1.5及更高版本.

Ideally this should be for Java versions 1.5 and above.

推荐答案

JDialog dialog = new JDialog(SwingUtilities.windowForComponent(this));
dialog.setModal(true);
dialog.setSize(200, 200);
dialog.setVisible(true);

这篇关于如何在Java applet中打开模式对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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