切换顶级窗口时如何使主机保持在对话框后面?

发布于 2024-08-24 08:46:48 字数 310 浏览 2 评论 0原文

以下情况:

我有一个 JFrame 并调用 JOptionPane.showInputDialog("test")。将显示模式对话框。

然后,当我切换到 Windows 中的另一个打开的窗口(假设是 Firefox),然后返回到我的 Java 应用程序(通过单击 Windows 任务栏中的选项卡或使用 ALT+TAB)时,将仅显示该对话框。

切换到我的应用程序时是否可以显示对话框后面的主框架? 例如,当您打开“首选项”对话框时,Eclipse 将按所需方式运行。 Eclipse 是 SWT,但也许在 Swing 中也是可能的!

Following situation:

I have a JFrame and call JOptionPane.showInputDialog("test"). The modal dialog will be shown.

When I then switch to another open window in Windows (let's say Firefox) and then return to my Java application (by clicking the tab in the windows task bar or with ALT+TAB) then only the dialog will be shown.

Is it possible to show the main frame behind the dialog when switching to my app?
E.g. Eclipse behaves the desired way when you open the Preferences dialog. Eclipse is SWT, but maybe it's possible in Swing too!

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

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

发布评论

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

评论(1

肤浅与狂妄 2024-08-31 08:46:48

我不知道如何使用 JOptionPane 的静态方法来执行此操作,因为您无权访问对话框本身。但是,您可能可以通过创建自己的对话框并添加侦听器来实现相同的目标,如下所示:

    final JDialog dialog = new JDialog();
    dialog.setTitle("Test Input");
    dialog.setModal(true);


    dialog.addWindowFocusListener(new WindowFocusListener() {

        @Override
        public void windowLostFocus(WindowEvent arg0) {

        }

        @Override
        public void windowGainedFocus(WindowEvent arg0) {
            frame.toFront();        
        }
    });

I don't know of a way to do this with JOptionPane's static methods, since you don't have access to the dialog itself. However, you can probably achieve the same thing by making your own dialog and adding a listener like this:

    final JDialog dialog = new JDialog();
    dialog.setTitle("Test Input");
    dialog.setModal(true);


    dialog.addWindowFocusListener(new WindowFocusListener() {

        @Override
        public void windowLostFocus(WindowEvent arg0) {

        }

        @Override
        public void windowGainedFocus(WindowEvent arg0) {
            frame.toFront();        
        }
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文