clear the java buffer

E

Emmanuel Freund

I have a strange error:

With this function:


public static ImageIcon loadImageIcon(String file, String iconName) {
return new ImageIcon(file+ '/' + iconName);
}
I first rename Image1.jpg to someImage.jpg and call this function with
loadImageIcon(myFile,someImage.jpg).
So Image1.jpg is loaded and paint (with some other functions of course).
Then during my execution, I rename Image2.jpg to someImage.jpg and call
loadImageIcon(myFile,someImage.jpg).
Then the Image loaded is still Image1.jpg.

Is that possible that Java remember that's the same function called with the
same variables, and so don't reload the Image and instead take the Image
from a buffer somewhere?
And if it's the case, how can we clear the buffer so the Image2.jpg is
reloaded?
Thanks,
 
A

Ann

Emmanuel Freund said:
I have a strange error:

With this function:


public static ImageIcon loadImageIcon(String file, String iconName) {
return new ImageIcon(file+ '/' + iconName);
}
I first rename Image1.jpg to someImage.jpg and call this function with
loadImageIcon(myFile,someImage.jpg).
So Image1.jpg is loaded and paint (with some other functions of course).
Then during my execution, I rename Image2.jpg to someImage.jpg and call
loadImageIcon(myFile,someImage.jpg).
Then the Image loaded is still Image1.jpg.

Is that possible that Java remember that's the same function called with the
same variables, and so don't reload the Image and instead take the Image
from a buffer somewhere?
And if it's the case, how can we clear the buffer so the Image2.jpg is
reloaded?
Thanks,
Try closing the file.
 
E

Emmanuel Freund

Try closing the file.

I may have missed something, but I used an ImageIcon which takes one string
and no file in its constructor... So I think all the openning-closing
operations are done in this constructor to which I don't have access.
So, how I close a file I haven't open ?
 
A

Andrew Thompson

ImageIcon which takes one string
and no file in its constructor..

So?
<http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/ImageIcon.html#ImageIcon(java.lang.String)>

Which, if you look at the source of ..
<http://www.physci.org/source.jsp?class=javax.swing.ImageIcon>
You'll notice it calls..
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)>

'caching'.

Don't use ImageIcons if you don't want the image cached,
load the bytes yourself and use ..
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#createImage(byte[])>

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top