将JFrame放在其他人之上 [英] Keep JFrame on top of others

查看:64
本文介绍了将JFrame放在其他人之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处于从主框架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屋!

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