是否可以将JFrame放在前面但不能集中精力? [英] Is it possible to bring JFrame to front but NOT focus?

查看:75
本文介绍了是否可以将JFrame放在前面但不能集中精力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Java应用程序(Swing GUI),该应用程序会定期弹出一个JFrame.

是否可以通过某种方式将窗口置于最前面(foo.setAlwaysOnTop(true)会更好),但是没有将其聚焦?

有些人在打字时不时将视线从屏幕上移开,以查看他们的键盘,而且我敢肯定,如果此窗口始终捕获键盘焦点,人们会很烦恼,因为这会导致他们迷失方向每次弹出时,都会有很多击键被忽略.

在其他情况下,即使用户实际上能够始终不用看键盘就能进行键入,弹出窗口并获得焦点也可能会导致弹出窗口本身发生不必要的操作(某些Tab +例如Enter组合,其中用户不小心选择了一个她本来不会选择的选项.

提前谢谢!

更新

如乔纳斯(Jonas)所建议的,foo.setFocusableWindowState(false);似乎可以在渲染窗口后调用(仅在Gnome上进行了测试).

这不起作用:

foo.setFocusableWindowState(false);
foo.setVisible(true);
foo.setFocusableWindowState(true);

但是,这:

foo.setFocusableWindowState(false);
foo.setVisible(true);
Thread.sleep(1000);
foo.setFocusableWindowState(true);

我将必须查看是否有可以捕捉/收听的事件,该事件可以让我在适当的时候执行foo.setFocusableWindowStatue(true);.

我认为我的问题已解决.

解决方案

这可能有效:

foo.setFocusableWindowState(false);

I'm writing a Java app (Swing GUI) that periodically pops up a JFrame.

Is it possible somehow to bring the window to front (foo.setAlwaysOnTop(true) would be even better) but without having it focus?

Some people move their eyes away from the screen from time to time to look at their keyboard while typing, and I'm sure that if this window would always capture the keyboard focus people would get really annoyed as it's causing them to lose quite a few keystrokes every time it pops up unnoticed.

In other cases, even when the user is actually capable of typing without looking at the keyboard all the time, having a window pop up and get focus could cause unwanted actions from the pop-up window itself (some Tab+Enter combination for example, where the user accidentally selects an option she really wouldn't had selected otherwise).

Thanks in advance!

Update

As Jonas suggests, foo.setFocusableWindowState(false); seems to work if called after the window has been rendered (tested on Gnome only).

This does not work:

foo.setFocusableWindowState(false);
foo.setVisible(true);
foo.setFocusableWindowState(true);

However, this does:

foo.setFocusableWindowState(false);
foo.setVisible(true);
Thread.sleep(1000);
foo.setFocusableWindowState(true);

I'll have to see if there's an event I can catch/listen to that allows me to do foo.setFocusableWindowStatue(true); when appropriate.

I consider my problem solved.

解决方案

This may work:

foo.setFocusableWindowState(false);

这篇关于是否可以将JFrame放在前面但不能集中精力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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