开发者

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

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 开发者_如何学Gothis 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜