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