Fullscreen Swing frames not focusing correctly in Linux (Windows is fine)

☆樱花仙子☆ 提交于 2019-12-23 10:42:20

问题


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

回答1:


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.




回答2:


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.




回答3:


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




回答4:


Since Java6 there is a FullScreen API. Consider using it: http://download.oracle.com/javase/tutorial/extra/fullscreen/index.html



来源:https://stackoverflow.com/questions/6667558/fullscreen-swing-frames-not-focusing-correctly-in-linux-windows-is-fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!