• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refreshing JLabel

 
Tim Berett
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Swing forum.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use
jl.setIcon(new ImageIcon(ImageIO.read(new File("c:/2.gif")));
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic