Less than 42 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Stupid threads  RSS feed

 
Milan Djukic
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Code is simple something like that:



When someone click on button i want to change label text and to close dialog after 1 second. This not works because label is refreshed when function is ended.
How to solve this?
 
Milan Djukic
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved

Instead of Thread.sleep() i make a thread where i dispose the dialog

Is this ok way?
 
Sandeep Kumar B
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post the updated code so that we can comment?
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see why that would help but I think dispose should be called on the EDT (Event Dispatch Thread) so if you have literally just created a new thread its a bit naughty ...

You should invoke it later on the EDT (your listener will be called from the EDT hence sleeping on it will block your GUI) , read this ...

SwingUtilities.invokeLater

 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recommended reading: Concurrency in Swing

edit And How to Use Swing Timers
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!