aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing Thread trouble " Watch "Swing Thread trouble " New topic
Author

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
Author
Greenhorn

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:
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 ]

Kathy Walrath<br />author, <a href="http://java.sun.com/docs/books/tutorial/" target="_blank" rel="nofollow">The Java Tutorial</a><br />editor, <a href="http://javadesktop.org" target="_blank" rel="nofollow">javadesktop.org</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swing Thread trouble
 
Similar Threads
using threads or there's another way?
Error loading image jar
JButton slow response time
screen repaint - newbie problem
display image selected by Jfilechooser on the content pane of the frame