全屏Swing框架在Linux下不能正确聚焦(Windows下可以)。[英] Fullscreen Swing frames not focusing correctly in Linux (Windows is fine)

本文是小编为大家收集整理的关于全屏Swing框架在Linux下不能正确聚焦(Windows下可以)。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有一个应用程序,该应用程序催生了几个全屏编织框架(基本上控制所有屏幕空间).我的问题是,某些帧上的某些按钮被设计为"开关屏幕",这基本上意味着显示另一个帧而不是当前的帧.

我在Windows中很容易地实现了这一点:

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

其中target是我要切换的框架.这是因为最初,我将所有帧设置为不可见,除了第一个"主"帧.

.

现在,当我将其移植到Linux环境中时,更改帧时会得到一个丑陋的"闪烁".在这一秒钟内,我可以看到我的桌面背景和应用程序背后存在的任何打开窗口.我以前在Windows中遇到了这个问题,并通过将目标框架放置在使旧的框架上不可见之前将其修复.

.

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

编辑:

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:

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

其他推荐答案

CardLayout 良好的单帧替代方案.您可以使用 combo box buttons

更新:此 example 带有Java版本1.6.0_20.

其他推荐答案

检查此线程以避免可能的内存缺乏,F.E.非常懒惰的排斥,通过创建新对象...等来失去性能

1/每个本机操作系统/添加JVM的可用内存有点不同且数量不同,有关详细信息,请使用一些Jprofiler(Live对象,变量,二手/可行的内存,通过GC'ING回收存储器)检查您的代码)

2/仅创建一个Jframe,另一个顶级容器将是Jdialog/Jwindow, 不要创建大量的jdialogs/jwindows,删除所有jcomponents的每一次重复使用更多信息在这里

3/GPU补丁和驱动程序的治疗问题

本文地址:https://www.itbaoku.cn/post/2091162.html

问题描述

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.

I have achieved this easily in Windows using this:

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

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.

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.

Any ideas on how to solve this Linux specific issue?

edit:

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();

From the JavaDocs:

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.

其他推荐答案

CardLayout might make a good single-frame alternative. You can navigate with a combo box or buttons or both.

Update: This example causes no flash on Ubuntu 10.04.3 LTS with Java version 1.6.0_20.

其他推荐答案

check this thread to avoids possible memory lack, f.e. very lazy repanting, lost performance by creating new Object(s) ... etc

1/ each Native OS assingned/adds available memory for JVM little bit different and with different amount, for details check your code by using some of JProfiler (live Objects, Variables, Used/Avalaible memory, recycle memory by GC'ing )

2/ create only one JFrame and other Top-Level Containers would be JDialog/JWindow, dont create tons of JDialogs/JWindows, every reUse by remove all JComponents more info here

3/ issue with healt of GPU patch and drivers