5

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
    please read [this thread][1] [1]: http://stackoverflow.com/questions/6586064/give-focus-to-a-panel-that-is-not-a-child-of-the-focused-window/6586196#6586196 – mKorbel Jul 12 '11 at 16:29
  • Thanks, I'll have a look at that. –  Jul 12 '11 at 16:39
  • @mKorbel - I don't think that is exactly what I'm looking for. The OP was dealing with keystrokes and his issue wasn't exactly the same as mine. –  Jul 13 '11 at 13:04
  • whats `KeyStrokes` has to do with `Focus` maybe more infos (really with uncompleted for all possible events) http://stackoverflow.com/questions/309023/howto-bring-a-java-window-to-the-front, or `OP `has some problem with set `Focus` to the concrete `JComponents` ??? – mKorbel Jul 13 '11 at 13:15
  • I have full screen frames which draw directly to the graphics card, instead of windows. The issue is not in explicitly changing focus to the frames, because I can do this in a Windows environment. My code, however, fails in Linux. I'm asking WHY it fails in Linux and HOW can I not make it fail in Linux. –  Jul 13 '11 at 13:20
  • just my curiosity, what API you using for that some OpenGL ??? – mKorbel Jul 13 '11 at 13:26
  • Java supports it, so no need for OpenGL. Look at my edit for how I create the frames. –  Jul 13 '11 at 13:29
  • see my post about that, maybe I'm wrong ... – mKorbel Jul 13 '11 at 13:44
  • why do you call `validate();` after `setVisible(true)`, there isn't reason to call for `Validate Container`, that nothing to do with laziest response, please take code (by @Andrew Thompson) 2nd. with `ClassName ImageCacheTest` http://stackoverflow.com/questions/6368160/how-to-convert-icon-from-jlabel-into-bufferedimage, un-comment //halfScreenSize = new Dimension(d.width - 11, d.height - 51); and then disable halfScreenSize = new Dimension(d.width / 2, d.height / 2); , that really hard for CPU & GPU, if flickering, freeze ..., then something is/are wrong inside PC/patch for OS – mKorbel Jul 26 '11 at 19:20
  • Did you try delaying `parent.setVisible(false);` by putting in into `SwingUtilities.invokeLater()`? That might do the trick. – jfpoilpret Jul 27 '11 at 10:59

4 Answers4

5

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
5
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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
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

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
1

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

Michał Šrajer
  • 30,364
  • 7
  • 62
  • 85