I have a file loading wizard as part of my Java application, allowing the user to add images to a room. Using common image editing software the user saves the .gif file to a specified folder that my application accesses to load the .gif file as a icon in a JLabel on a JPanel. This is done on step 3 of the file loading wizard using a new ImageIcon, which works fine and the icon shows.
If the user goes back a previous step (file is deleted from the specified folder when the JPanel reloads the previous step) and updates the image using common image editing software and resaves the file using the same name. Then forward to step 3 of the file loading wizard the new ImageIcon is called again but this time it still shows the width and height of the old deleted image file. The lastModified value on the File object is changing, so I assume the File object is loading the updated file. But for some reason the ImageIcon object is still pulling values from the deleted file. However if the name of the file is changed on the previous step then the ImageIcon will show the correct width and height values on step 3 of the file loading wizard.
Is the image cached some where that the new ImageIcon object is finding?
Here is a code snippet from my file loading wizard. This is inside the method that builds the wizard step JPanel.
...Other Code Here...
int height = 0;
int width = 0;
File file = new File(fileLocation);
String[] fileList = file.list();
if(fileList.length == 1){
OrginialFileName = fileList[0];
//Shouldn't this create a new instance of an ImageIcon?
//Do I need to clear a cache somewhere?
//ImageIcon object is not global and is only used locally in this conditional statement.
ImageIcon imageIcon = new ImageIcon(file + "\\" + OrginialFileName);
height = imageIcon.getIconHeight();
width = imageIcon.getIconWidth();
/*The width and height are pulling from the deleted file.
I have verified that the new file is the only file in the directory where the file loading
wizard is pulling from and the window's file properties screen shows the correct dimensions.*/
...Other Code Here...