Is it possible to bring JFrame to front but NOT focus?(是否可以将 JFrame 放在前面但不聚焦?)
问题描述
我正在编写一个定期弹出 JFrame 的 Java 应用程序(Swing GUI).
I'm writing a Java app (Swing GUI) that periodically pops up a JFrame.
是否有可能以某种方式将窗口置于前面(foo.setAlwaysOnTop(true) 会更好)但没有使其成为焦点?
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.
在其他情况下,即使用户实际上能够在不一直看键盘的情况下打字,弹出一个窗口并获得焦点也可能会导致弹出窗口本身的不需要的操作(一些 Tab
+Enter
组合,例如,用户不小心选择了一个她本来不会选择的选项).
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).
提前致谢!
更新
正如 Jonas 建议的那样,如果在渲染窗口后调用 foo.setFocusableWindowState(false);
似乎可以工作(仅在 Gnome 上测试过).
As Jonas suggests, foo.setFocusableWindowState(false);
seems to work if called after the window has been rendered (tested on Gnome only).
这不起作用:
foo.setFocusableWindowState(false);
foo.setVisible(true);
foo.setFocusableWindowState(true);
但是,这确实:
foo.setFocusableWindowState(false);
foo.setVisible(true);
Thread.sleep(1000);
foo.setFocusableWindowState(true);
我必须看看是否有我可以捕捉/收听的事件允许我在适当的时候执行 foo.setFocusableWindowStatue(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.
推荐答案
这可能有效:
foo.setFocusableWindowState(false);
这篇关于是否可以将 JFrame 放在前面但不聚焦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以将 JFrame 放在前面但不聚焦?
基础教程推荐
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01