将JFrame放在其他人之上 [英] Keep JFrame on top of others
问题描述
我处于从主框架FrameA
创建框架FrameB
的情况.当用户正在使用FrameB
时,即使用户意外单击FrameA
,我也希望它位于FrameA
之上.
I am in a situation where I create a frame FrameB
from my main frame FrameA
. When the user is working on FrameB
I would like it to be on top of FrameA
even when the user accidentally clicks on FrameA
.
推荐答案
是否必须使用JFrame?
Do you have to use a JFrame?
如果使用JDialog而不是JFrame并通过构造函数将FrameA分配为对话框的所有者,则它将始终保留在框架的顶部. (例如:如何设置JFrame作为JDialog的父级)
If you use a JDialog instead of a JFrame and assign FrameA as the owner of the dialog through the constructor it will always remain on top of the frame. (Example: How to set the JFrame as a parent to the JDialog)
否则,您可以从window类使用setAlwaysOnTop(),但这可能取决于操作系统/窗口管理器.
Otherwise you can use setAlwaysOnTop() from the window class, but this can be dependent on the operating system/window manager.
这篇关于将JFrame放在其他人之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!