File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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( File("c:/1.gif")));
j.add(jp); jp.add(jl);;
//Some waiting here, the panel does not show 2.gif.
jl = new JLabel(new ImageIcon( File("c:/2.gif")));

Michael Ernest
High Plains Drifter

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
jl.setIcon(new ImageIcon( File("c:/2.gif")));
I agree. Here's the link:
subject: Refreshing JLabel
jQuery in Action, 3rd edition