How can i set a jFrame to be always on top and focuse enabled until it is closed?

风格不统一 提交于 2019-12-17 20:07:03

问题


There are two different Frames in my program and the second one open when i click the jButton is the first frame,so when the second frame is opened, I want the second frame to be always on top and focused until it is close. user can't be allowed to do anything in the first window until the second window is closed. how can i do this?


回答1:


JFrame frame = new JFrame ();
frame.setAlwaysOnTop (true);

If you want frame to be always focused, you probably need to use modal dialog instead of JFrame:

JDialog dialog = new JDialog ();
dialog.setModal (true);
dialog.setAlwaysOnTop (true);
dialog.setModalityType (ModalityType.APPLICATION_MODAL);


来源:https://stackoverflow.com/questions/14795995/how-can-i-set-a-jframe-to-be-always-on-top-and-focuse-enabled-until-it-is-closed

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