Can Java display a dialog without changing the active window?

爷,独闯天下 提交于 2019-12-20 02:24:07

问题


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?

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, 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 );

回答1:


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.



来源:https://stackoverflow.com/questions/17179548/can-java-display-a-dialog-without-changing-the-active-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!