• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Swing Thread trouble

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an image viewer program in which I use a label with an Icon to view images. The left and right navigation buttons work, but I what I really want is a startShow and stopShow buttons. The startShow btn should iterate through all the images automatically with a 2 second pause starting with the current one and stopShow button should stop the show at the present image. If I add no pause, it actually works but is too fast. If I add a pause, it doesn't display any images. What am I doing wrong?
Here is some of the relevant code.
 
Author
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you're waiting in the event thread, which stops all event-processing and painting in the app. What you should use instead is a Swing Timer. You can find information about Swing Timers here:
http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
In fact, there's some code in there which is very close to what you need -- it performs an action once a second for as long as there's anything to do.
[ April 29, 2004: Message edited by: Kathy Walrath ]
 
This tiny ad is wafer thin:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic