Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  JDialog problem with showing its content when modal==false.  (Read 2039 times)
0 Members and 1 Guest are viewing this topic.
Offline zappsweden

Junior Member




Java games rock!


« Posted 2006-05-25 12:29:46 »

I want to have JDialog popping up in my game showing some info and then disappear after 2-3 seconds. Obviously, having a modal JDialog with a "OK" button to close it will get hazzling so therefore I want no such button instead close it automatically.

 So, I need show() followed by a sleep and then hide(). If I use modal, then i need the sleep inside the JDialog since modal JDialog stops the outside code until it hide(). But, if I instead use a non modal one and put the sleep outside the JDialog and then close it from outside as well, i get a strange way of the JDialog not painting itself. The text does not get shown on the JDialog unnless it is Modal. Strange. I get kind of the same problems I had (since i use passive rendering) of having to force paint with paintImmediately but in JDialog there is no such method I can use?

What to do?

Offline Mr_Light

Senior Member




shiny.


« Reply #1 - Posted 2006-05-25 15:18:25 »

read up on the eventque, if you are making the the thread that paint the Dialog sleep then offcourse it isn't gonna paint.

also rolling your own sleep(inteval)...action is also not needed have a look at Timer resp TimerTask

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline zappsweden

Junior Member




Java games rock!


« Reply #2 - Posted 2006-05-31 20:00:42 »

The thing is, inside my class extending jdialog i had


  public void show(String text)
  {
    this.jLabel1.setText(text);
    this.show();
    XThread.delay(1500); /*same as, try sleep catch exception*/
    this.hide();
  }

If the object is modal==false when running this method, it shows, waits 1.5 seconds and then closes as intended. If modal==true then it does not close, why?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kova

Senior Member





« Reply #3 - Posted 2006-06-01 01:45:50 »

I haven't worked with this stuff before... how about simple compileable example of the problem? I can't truly understand the problem.
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 9


Age of Conquest makes your day!


« Reply #4 - Posted 2006-06-01 02:24:35 »

Swing is SINGLE-threaded, i.e. if you put the Swing thread to sleep using "XThread.delay(1500);" - nothing will happen, i.e. no redraws anything. Your sleep call puts Swing to sleep.

Instead, create a separate thread which hides the dialog box after a predefined time:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
Thread sleepThread = new Thread() {
  public void run() {
    Thread.sleep(1500);
    dialog.setVisible(false);
  }
};
// start hiding thread and continue with current (Swing) thread
sleepThread.start();

//

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2006-06-03 11:35:07 »

The thing is, inside my class extending jdialog i had


  public void show(String text)
  {
    this.jLabel1.setText(text);
    this.show();
    XThread.delay(1500); /*same as, try sleep catch exception*/
    this.hide();
  }

If the object is modal==false when running this method, it shows, waits 1.5 seconds and then closes as intended. If modal==true then it does not close, why?

The real answer is that dialog.show() or dialog.setVisible(true) is blocking when the dialog is modal - as long as the dialog is visible.

If you try to run the closing-code it after dialog.show() that code will never run.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
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.

xsi3rr4x (56 views)
2014-04-15 18:08:23

BurntPizza (54 views)
2014-04-15 03:46:01

UprightPath (67 views)
2014-04-14 17:39:50

UprightPath (50 views)
2014-04-14 17:35:47

Porlus (67 views)
2014-04-14 15:48:38

tom_mai78101 (91 views)
2014-04-10 04:04:31

BurntPizza (152 views)
2014-04-08 23:06:04

tom_mai78101 (248 views)
2014-04-05 13:34:39

trollwarrior1 (205 views)
2014-04-04 12:06:45

CJLetsGame (212 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!