位于主应用程序窗口顶部的可最小化的JFrame [英] Minimizable JFrame that stays on top of main application window

查看:110
本文介绍了位于主应用程序窗口顶部的可最小化的JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序弹出一个对话框.用户通常希望在此对话框和应用程序窗口之间来回切换一段时间.我希望此对话框停留在顶部,这样它就不会隐藏在主应用程序窗口的后面.但是同时,我希望对话框具有一个最小化按钮,以便在一段时间内不需要时可以摆脱它.

My apps pops up a dialog. Users usually want to switch back and forth between this dialog and the application window for a period of time. I want this dialog to stay on top, so that it doesn't get hidden behind the main application window. But at the same time I want the dialog to have a minimize button so that it can get out of the way if it's not needed for a while.

这是我尝试过的:

  • 使用无模式JDialog-对话框很好地位于前面,但是它没有最小化按钮,也没有自己的任务栏按钮

  • use a modeless JDialog - the dialog stays in front nicely, but it doesn't not have a minimize button, and it doesn't have its own taskbar button either

使用JFrame-对话框现在具有最小化按钮和其自己的任务栏按钮,但是当主窗口获得焦点时,该对话框将隐藏在其后.

use a JFrame - the dialog now has a minimize button and its own taskbar button, but when the main window gets focus the dialog is hidden behind it.

使用JFrame并在对话框上添加WindowListener.windowDeactivated(){this.toFront()}.问题在于toFront()还会设置焦点,从而获得怪异的焦点闪烁效果.

use a JFrame and add WindowListener.windowDeactivated() { this.toFront() } on the dialog. The problem with this is that toFront() also sets the focus, so that you get a weird focus flickering effect.

使用带有setAlwaysOnTop的JFrame-这是最简洁的解决方案,但是现在该窗口将停留在所有其他应用程序的顶部,而不仅仅是我的应用程序.

use a JFrame with setAlwaysOnTop - this is the neaerest solution, but now the window will stay on top of all other applications, not just my application.

如果toFront仅将JFrame带到前面而不改变焦点,那将很容易,但是不幸的是事实并非如此.还有另一种更改JFrame Z顺序的方法吗?

It would be easy if toFront just brought the JFrame to the front without changing the focus, but unfortunately that is not the case. Is there another way to change JFrame Z-order?

我只是想到,如果有一种简单的方法可以汇总" JDialog,即最小化它而不是将其拖到任务栏,那也可以解决我的问题.

edit: It just occurred to me that if there were an easy way to "roll-up" a JDialog, i.e. minimize it but not to the taskbar, that would solve my problem too.

推荐答案

为什么不监听框架中的focusGained事件,然后在对话框上使用setZOrder/toFront呢? (不确定是否可以使用,但值得一试).

Why not listen for the focusGained event in the frame and then use setZOrder/toFront on the dialog at that point? (Not sure this will work but worth a shot).

这篇关于位于主应用程序窗口顶部的可最小化的JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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