File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Refreshing JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Refreshing JLabel" Watch "Refreshing JLabel" New topic
Author

Refreshing JLabel

Tim Berett
Ranch Hand

Joined: Jun 14, 2002
Posts: 35
Hi all,

I have a pictorial JLabel which I want it changed during the program code. Apparently, when I set it to a new pic, it does not refresh. How do I refresh it?

Sample Code Extract
--------------------
JFrame j = new JFrame();
JPanel jp = new JPanel();
JLabel jl = new JLabel(new ImageIcon(ImageIO.read(new File("c:/1.gif")));
j.add(jp); jp.add(jl);
j.show();
//Some waiting here, the panel does not show 2.gif.
jl = new JLabel(new ImageIcon(ImageIO.read(new File("c:/2.gif")));



Tim
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Moving to the Swing forum.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
use
jl.setIcon(new ImageIcon(ImageIO.read(new File("c:/2.gif")));
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Refreshing JLabel