全屏Swing框架在Linux中无法正确聚焦(Windows很好) [英] Fullscreen Swing frames not focusing correctly in Linux (Windows is fine)

查看:76
本文介绍了全屏Swing框架在Linux中无法正确聚焦(Windows很好)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序生成了几个全屏无装饰帧(基本上控制所有屏幕空间).我的问题是,某些框架上的某些按钮旨在切换屏幕",这基本上意味着要显示另一框架而不是当前框架.

I've got an application which spawns several fullscreen-no-decoration frames (basically controlling all screen space). My problem, is some buttons on certain frames are designed to "switch screens", which basically means showing another frame instead of the current one.

我使用以下方法在Windows中轻松实现了这一点:

I have achieved this easily in Windows using this:

target.setVisible(true);
target.requestFocus();
this.parent.setVisible(false);

target是我要切换到的帧.之所以可行,是因为最初,我将所有帧设置为不可见,除了第一个主"帧.

Where target is the frame I'm switching to. This works because initially, I set all frames to not visible except for the first "main" frame.

现在,当我将其移植到Linux环境中时,在更换框架时会出现难看的闪烁".在这瞬间,我可以看到我的桌面背景以及应用程序背后存在的所有打开的窗口.我以前在Windows中遇到过此问题,并通过在使旧框架不可见之前集中目标框架来解决此问题.

Now, when I port this into a Linux environment, I get an ugly "flashing" when changing frames. In this split second, I can see my desktop background and any open windows I have that exist behind my application. I had this issue in Windows before and fixed it by focusing the target frame before making the old one invisible.

关于如何解决此Linux特定问题的任何想法?

Any ideas on how to solve this Linux specific issue?

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setUndecorated(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(0,0,screenSize.width, screenSize.height);
this.getContentPane().setLayout(null);
setVisible(true);
validate();

推荐答案

target.requestFocus();

来自JavaDocs:

From the JavaDocs:

请注意,不建议使用此方法,因为其行为取决于平台.相反,我们建议使用requestFocusInWindow().如果您想了解更多有关焦点的信息,请参见如何使用焦点子系统,这是 Java教程中的部分.

Note that the use of this method is discouraged because its behavior is platform dependent. Instead we recommend the use of requestFocusInWindow(). If you would like more information on focus, see How to Use the Focus Subsystem, a section in The Java Tutorial.

这篇关于全屏Swing框架在Linux中无法正确聚焦(Windows很好)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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