my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes Swing Thread trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing Thread trouble " Watch "Swing Thread trouble " New topic

Swing Thread trouble

Lu Battist
Ranch Hand

Joined: Feb 17, 2003
Posts: 104
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.
Kathy Walrath

Joined: Apr 26, 2004
Posts: 13
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:
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 ]

Kathy Walrath<br />author, <a href="" target="_blank" rel="nofollow">The Java Tutorial</a><br />editor, <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Swing Thread trouble
It's not a secret anymore!