• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display labels one at a time in a jbutton ActionListener

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic