Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ALT+TAB makes my JDialog invisible?  (Read 5373 times)
0 Members and 1 Guest are viewing this topic.
Offline zappsweden

Junior Devvie

Java games rock!

« Posted 2006-07-26 19:25:56 »

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).
Offline zappsweden

Junior Devvie

Java games rock!

« Reply #1 - Posted 2006-08-03 15:38:32 »

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) {

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

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().  Roll Eyes

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?
Offline Kova

Senior Devvie

« Reply #2 - Posted 2006-08-04 01:49:41 »

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: ... 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 see, even when green is maxed, you were clicking inside the bounds of the white box (the green and the white bounds overlap, even though the white box is invisible). This caused your code to enter the "wrong" block, the one for the white box.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CommanderKeith
« Reply #3 - Posted 2006-08-08 04:53:54 »

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?

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.

Offline Kova

Senior Devvie

« Reply #4 - Posted 2006-08-08 10:59:37 »

actually, as I remember from that article about painting, you aren't supposed to call paintImmediatly() at all... only repaint()
Offline zappsweden

Junior Devvie

Java games rock!

« Reply #5 - Posted 2006-08-09 22:37:33 »

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


instead of my


Nothing has worked so far.
Offline zappsweden

Junior Devvie

Java games rock!

« Reply #6 - Posted 2006-08-16 21:55:36 »

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);; /*alt+tab can destroy dialogs!*/ 

Pages: [1]
  ignore  |  Print  

Riven (845 views)
2019-09-04 15:33:17

hadezbladez (5789 views)
2018-11-16 13:46:03

hadezbladez (2602 views)
2018-11-16 13:41:33

hadezbladez (6205 views)
2018-11-16 13:35:35

hadezbladez (1498 views)
2018-11-16 13:32:03

EgonOlsen (4733 views)
2018-06-10 19:43:48

EgonOlsen (5789 views)
2018-06-10 19:43:44

EgonOlsen (3275 views)
2018-06-10 19:43:20

DesertCoockie (4174 views)
2018-05-13 18:23:11

nelsongames (5500 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!