Java 可以在不更改活动窗口的情况下显示对话框吗? [英] Can Java display a dialog without changing the active window?

查看:35
本文介绍了Java 可以在不更改活动窗口的情况下显示对话框吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Frame 上方显示一个模式(进度)对话框,即使 Frame 不是活动窗口.但是,显示对话框会使其或其所有者成为活动窗口.有没有一种方法可以显示对话框而不使其或其所有者成为活动窗口——特别是在 Windows 平台上?

I'd like to display a modal (progress) dialog above a Frame, even if that Frame isn't the active window. However, displaying a dialog causes it or its owner to become the active window. Is there a way to display a dialog without it or its owner becoming the active window -- specifically, on a Windows platform?

我想这样做的原因是:我的 Frame 定期刷新自身并在刷新时显示其模式进度对话框.现在我的应用程序只在它处于活动窗口时刷新.

The reason I'd like to do this is: periodically my Frame refreshes itself and displays its modal progress dialog while refreshing. Right now my application only refreshes while it's the active window.

SSCCE,因为人们要求它:

SSCCE, since people are asking for it:

Frame frame = new JFrame();
frame.setVisible( true );
// 30 seconds later (using a Timer/TimerTask)
Dialog dialog = new JDialog( frame, ModalityType.DOCUMENT_MODAL );
dialog.setVisible( true );

推荐答案

我不认为你可以用模态对话框来做到这一点.

I don't think you can do this with a modal dialog.

但是以下内容适用于非模态对话框:

However the following works for a non-modal dialog:

dialog.setFocusableWindowState( false );
dialog.setVisible(true);
dialog.setFocusableWindowState( true );

当对话框显示时,它不会获得焦点,但如果您点击它,它将获得焦点.你可以在模态对话框上试试这个,看看会发生什么.

When the dialog displays it will not have focus, but if you click on it, it will gain focus. You could try this on a modal dialog to see what happens.

这篇关于Java 可以在不更改活动窗口的情况下显示对话框吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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