问题描述
我想使用JLabel(Icon)显示来自我网站的图像( http://xxx.xxx.xxx.xxx/java_pic/test.jpg ).我有一个刷新按钮来新建一个新的JLabel和ImageIcon(以获取最新的图像)该程序成功运行...但是当我上传新图像以覆盖旧图像时( http://xxx.xxx.xxx.xxx/java_pic/test.jpg ),我按下了刷新按钮……什么也没发生!我重新启动程序...现在出现新图像...为什么?当我再次新建ImageIcon时,它不应该从网站上重新加载图像吗?
I would like to use JLabel(Icon) to show a Image which is from my website(http://xxx.xxx.xxx.xxx/java_pic/test.jpg).And I have a refresh button to new a new JLabel and ImageIcon(in order to get the newest image)The program run successfully...but when I upload a new image to override the old one(http://xxx.xxx.xxx.xxx/java_pic/test.jpg), I press the refresh button... nothing happened!I restart my program... and the new image now appears... why?Shouldn't it reload the image from website when I new a ImageIcon again?
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()...为什么?谢谢!
when I click the refresh button, it would call the refresh()...why?Thanks!
推荐答案
图像已缓存.刷新以清除缓存:
The image is cached. Flush to clear the cache:
imageIcon.getImage().flush();
这篇关于ImageIcon不会为具有相同URL的新图像更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!