Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (606)
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 2142 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) {
this.blablablaDialog.hide()
...
...
...
  }

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 »

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

super.setIgnoreRepaint(true);

instead of my

super();
this.setIgnoreRepaint(true);

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);
     this.game.repaintAllDialogs(); /*alt+tab can destroy dialogs!*/ 
}



Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Elsealabs (17 views)
2014-12-28 10:39:27

CopyableCougar4 (20 views)
2014-12-28 02:10:29

BurntPizza (25 views)
2014-12-27 22:38:51

Mr.CodeIt (15 views)
2014-12-27 04:03:04

TheDudeFromCI (20 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

rwatson462 (58 views)
2014-12-15 09:26:44

Mr.CodeIt (47 views)
2014-12-14 19:50:38

BurntPizza (98 views)
2014-12-09 22:41:13

BurntPizza (116 views)
2014-12-08 04:46:31
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
java-gaming.org 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‑gaming.org
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!