Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ImageIcon不更新具有相同URL的新图像_Java_Swing - Fatal编程技术网

Java ImageIcon不更新具有相同URL的新图像

Java ImageIcon不更新具有相同URL的新图像,java,swing,Java,Swing,我想使用JLabel(图标)显示来自我的网站()的图像。 我有一个刷新按钮来新建一个新的JLabel和ImageIcon(以便获得最新的图像) 程序成功运行…但当我上载新图像以覆盖旧图像()时,我按了刷新按钮。。。什么也没发生! 我重新启动我的程序。。。现在新的图像出现了。。。为什么? 当我再次新建图像图标时,它不应该从网站重新加载图像吗 public void refresh(){ URL iconUri = null; iconUri = new URL("http://XX

我想使用JLabel(图标)显示来自我的网站()的图像。 我有一个刷新按钮来新建一个新的JLabel和ImageIcon(以便获得最新的图像) 程序成功运行…但当我上载新图像以覆盖旧图像()时,我按了刷新按钮。。。什么也没发生! 我重新启动我的程序。。。现在新的图像出现了。。。为什么? 当我再次新建图像图标时,它不应该从网站重新加载图像吗

public void refresh(){
    URL iconUri = null;
    iconUri = new URL("http://XXX.XXX.XXX.XXX/java_pic/test.jpg");
    ImageIcon imageIcon = new ImageIcon(iconUri);
    JLabel imageLabel = new JLabel(imageIcon);
    frame.add(imageLabel);
    ...
    ...
}
当我单击刷新按钮时,它会调用refresh()…为什么?
谢谢

图像被缓存。刷新以清除缓存:

imageIcon.getImage().flush();

非常感谢你!这管用!另一个问题是,我是否可以在“new JLabel(imageIcon);”之后立即刷新imageIcon?