• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

screen repaint - newbie problem

 
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 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:
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic