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

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

问题描述

我正在尝试在 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 小程序中打开模态对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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