Basically, I am trying to create an app, that displays images.
filename variable is a path to an image that I want to display. After I start an app, an Image is displayed, but then, when I remove the image from a hard drive (or change other image to the filename name) I don’t get any other Image, just the same as before.
public static void main(final String[] args) {
String filename = "C:\\temp\\1.jpeg";
JFrame frame = new JFrame();
frame.getContentPane().add(new JLabel(new ImageIcon(filename)));
frame.pack();
frame.setVisible(true);
// Mouse Listener is only to display another JFrame after mouseClicked event
frame.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
main(args);
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
});
}
The image is cached. You need to force it to reload by doing either: