如何将jFrame设置为始终位于顶部并且在关闭之前启用焦点? [英] How can i set a jFrame to be always on top and focuse enabled until it is closed?

查看:285
本文介绍了如何将jFrame设置为始终位于顶部并且在关闭之前启用焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序中有两个不同的框架,第二个框架在我点击jButton是第一个框架时打开,所以当第二个框架打开时,我希望第二个框架始终在顶部并聚焦直到它关闭。在第二个窗口关闭之前,不允许用户在第一个窗口中执行任何操作。我怎样才能做到这一点?

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?

推荐答案

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

如果你想让帧始终聚焦,你可能需要使用模态对话框而不是JFrame: / p>

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

这篇关于如何将jFrame设置为始终位于顶部并且在关闭之前启用焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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