This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Sleep before command above?  RSS feed

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there!
In a Class extending a JFrame, I've got a contentPane and inside a JLabel "someJLabel" set to be NOT visible. There is also a JButton on the panel and if I click the button, the following code will be executed:
someJLabel.setVisible(true);
try {
Thread.sleep(1000);
}
catch(InterruptedException ie) {
}
Does anyone know why the Label becomes visible AFTER the 1000 milliseconds I waited because of Thread.sleep(1000)? Does anyone know a solution?
Thanks in advance
Florian Meyer
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't sleep on the event handling thread without preventing further event handling or painting; if the event handler is blocked, the setVisible() call won't have any effect. Tell us what you're actually trying to accomplish here, and we can probably tell you how to do it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!