0

Hi!
I'm totaly new to java, but I have been writing a bit in other langages. So my app is generating a .png file representing the structure of graph. This it already made, and it's working fine.I'm generating a .png every time graph's structure is changing(for example when user is adding new node or edge). But I have problem with showing this .png file. I'm doing it like this:

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
Icon icon = new ImageIcon("graph.png");
jLabel3.setIcon(icon);
}

and if there where no image before it's displaying it ok. but after that, it's still displaying the old image, even when the file graph.png has already changed. do have any idea how to solve this problem ??

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Silx
0

You probably need to flush the Image resources. Try adding this to see if it gets rid of the cached image

ImageIcon oldIcon = (ImageIcon)jLabel3.getIcon();
oldIcon.getImage().flush();
Icon icon = new ImageIcon("graph.png");
jLabel3.setIcon(icon);

Is there a reason that it has to generate a .png instead of rendering directly to the screen?

0

That's exactly what i've been looking for... I still can't bealive it was so simple :P Thanks a lot!!!
I have to use these .png coz I'm using outer program go generate them.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.