ALT+TAB makes my JDialog invisible?

With no need for more than perhaps 20 frames/second I have decided to go for a pure Swing Passive Rendering approach with my graphics. The thing is, since repaint() is unreliable I use paintImmediately() instead to be able to force paints whenever I want. The problem with it, paintImmediately seem to do what active rendering do and take control over the whole screen. That mean, I cannot have a UI where I have a Map covering the whole screen and then put neat JDialogs on top of the map since paintImmediately() conflicts with the JDialog and paint over the JDialog. Is there any way of getting paintImmediately (or any other way doing passive rendering) that means I can controls the frame rate and still have no conflicts?

By the way, I use non-modal JDialogs (if that makes any difference).

I got another related problem now. It seems absurd. I thought the point with using Swing was that you would not need to control buffers, active rendering and not having to take any consideration whatsoever of graphic memory or platform. Just being able to use paintImmediately when i needed something urgently painted and then use some sleep(millis) before some operations preventing that the paintImmediately did not interfer and create strange graphic bugs. Seems I was wrong…

Now, the problem is when i ALT+TAB out from and then back into the game. If I have a JDialog on the Screen when i do this, it will be invisible when i return but still be active internally. It is “like it is there”, I have to close it down on invisible JDialogs close button.

I tried setIgnoreRepaint(true) by making a MyJPanel extends JPanel using it for all my JPanel in the game. MyJPanel sets “this.setIgnoreRepaint(true);” .

I even tried to close the JDialog when ALT+TAB i.e using eventhandler to close all dialogs when losing focus

void this_focusLost(FocusEvent e) {
this.blablablaDialog.hide()



}

and it does not work! JDialog is still there, but invisible, when i return (in both modal and non-modal JDialog). ???

I am soon convinced that Swing cannot even be used purely to make turn based strategy games with its limit so maybe I would have to be forced switching to Active Rendering and paintingloops(). ::slight_smile:

By the way, with Active rendering, I could not use Swing JPanel on the screen because i would paint over them from the painting loop? So, i need to make every little JLabel, JButton and all that from the painting loop and not using Swing layout managers?

hide():
@Deprecated
public void hide()

try using setVisible(false) …

if you made MyJPanels that extend JPanel, shouldn’t you call super.setIgnoreRepaint(true) instead of this? Don’t know if it makes any difference. But why do you call it, then system triggered paint request will be ignored and you’ll have to paint yourself.

something that’s not visible shouldn’t react at all…
try to change focus to your “main” JPanel in some test button you’ll click after you alt-tab back and problem is still there… and try then, maybe your dialog is receving focus after alt-tab?

EDIT: http://java.sun.com/products/jfc/tsc/articles/painting/ … check it out
try resizind your app after jdialog goes invisible… that should trigger system repaint

EDIT2: I’ve stumbled on this right now, might help you, they’re talking about panels in splitpane?:

You have to call paintImmediately() from the AWT Event Dispatch Thread because otherwise there will be conflicts between the EDT and your thread that will be effectively doing active rendering.

actually, as I remember from that article about painting, you aren’t supposed to call paintImmediatly() at all… only repaint()

I tried setVisible(false) instead of hide(), i tried setSize on the JFrame but to no result. Something is calling repaint() that is for sure. I managed to put a boolean flag on my JPanel that i use for the map and set the flag so it did not do anything on repaint() unless i had the flag set. Result was that instead, the area just got black so yeah I got the painting stopped.

Something is making maybe many of my JPanels to call repaint when i alt+tab despite I have ignoreRepaint(true), strange…
Yes, i also tried the

super.setIgnoreRepaint(true);

instead of my

super();
this.setIgnoreRepaint(true);

Nothing has worked so far.

I finally found a solution to this. Since the JDialogs dissappear I figured my not repaint them? So, i made one grand “repaintAllDialogs()” in my game that i call and it repaints all Dialogs even if not visible. Not visible means they wont use hardly any CPU anyways so I see no harm.

All my JFrame and JPanel that are opening JDialogs in the game now has

public void paintComponent(Graphics g)
{
super.paintComponent(g);
this.game.repaintAllDialogs(); /alt+tab can destroy dialogs!/
}