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