aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes screen repaint - newbie problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "screen repaint - newbie problem" Watch "screen repaint - newbie problem" New topic
Author

screen repaint - newbie problem

Lu Battist
Ranch Hand

Joined: Feb 17, 2003
Posts: 104
I trying to write an image viewer. I have my left and right buttons working but when I want to let the user press the show button to cycle through images, the screen doesn't refresh at the right time. I was hoping someone could tell me a simple fix or if my whole approach is wrong.
I get a list of images in a directory and put the files into a vector.
I use a JLabel to display the images.
The real problem is that the repainting of the screen isn't happing until after the action performed method complete. That is fine for the left and right buttons but not for the slide show button.
Here my button handlers:

Here is the showImage method:
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

This is your typical Swing event thread issue. When you move into an actionPerformed method of an ActionListener, this method has to complete before any of SWING repainting methods get called from the SWING Thread. There are numerous articles on the net about this if you search Google.
Here is a pretty good article from java.net on the subject. The author of the article gives in interesting solution to this common problem. And while I don't agree entirely with his methodology, everything he shows you when building up to his point is worth the reading and it will show you currrent solutions that he feels are inadequate although I find them quite useful.


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: screen repaint - newbie problem