The moose likes Swing / AWT / SWT and the fly likes Display an image for a set time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Display an image for a set time" Watch "Display an image for a set time" New topic

Display an image for a set time

Chris Ramsey
Ranch Hand

Joined: Sep 15, 2003
Posts: 34
I have an application that should load an image to be set as an icon for a JLabel from JPEG files. The file names are numbers ie. (0.jpg, 1.jpg, ...) so that i can choose the files with a loop and use the loop index as the image name to be retrieved.
Depending on some user action the picture should be set visible for about 5 seconds, set invisible, unload the image, retrieve the next image and then depending on the user action, show it again for another couple of seconds. The way I am doing it it takes the image a long time to be shown. I thought by loading it before I would actually need it that it would speed things up, but thats not what happens. It takes a long time for the image to visible. I have a resource manager class responsible for creating the images from the jpegs. They also have to be resized so that may be why it is taking so long. Here's the resource class makeImage method.

The load and show picture methods are in another class that defines a picture panel

So if the user action is appropriate then the picture panel should be displayed and another one loaded up. I thought using the SwingUtlities would solve any thread issues. Is there some additional thread sequencing that I should do in order for the action to be faster? Thanks for the suggestions.

[ June 23, 2004: Message edited by: Chris Ramsey ]
[ June 23, 2004: Message edited by: Chris Ramsey ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
This works fast on my computer. If it's still too slow for you I suggest you explore using the createCompatibleImage method in the GraphicsConfiguration class. I've read it can make a difference in rendering time.
Chris Ramsey
Ranch Hand

Joined: Sep 15, 2003
Posts: 34
Thanks Craig! Will try this approach.
I agree. Here's the link: http://aspose.com/file-tools
subject: Display an image for a set time
Similar Threads
JLabel , image
Newbie question on JGoodies-FormLayout/DefaultFormBuilder...
JGoodies DefaultFormBuilder and separator question
Any idea why my jpeg isn't showing?
Different Cursors