• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display labels one at a time in a jbutton ActionListener  RSS feed

 
switch hacker
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried every way I can think of to solve this problem. I'm trying to display 4 labels when a person clicks on a jbutton. I want each label to be displayed one at a time rather than all at once. it appears that nothing will be displayed until the actionlistener has gone through the entire actionlistener class. Is this how actionListeners work? I've tried to put timedelays between label.setVisible(true);, but it doesn't matter, it still outputs all the labels at once.

PLEASE HELP!!!
THANKS IN ADVANCE
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

All GUI updates should happen on the Event Dispatch Thread. To solve your problem, you need to spawn a Runnable instance, encapsulate all your add label, wait etc logic inside it, and use it along with SwingUtilities#invokeLater
More details on threading in Swing can be found at http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!