我想使用 JLabel(Icon) 来显示来自我网站的图像(http://xxx.xxx.xxx.xxx/java_pic/test.jpg)。
我有一个刷新按钮来新建一个新的 JLabel 和 ImageIcon(为了获取最新的图像)
程序运行成功...但是当我上传新图像来覆盖旧图像时(http://xxx.xxx.xxx.xxx/java_pic/test.jpg),我按下刷新按钮...什么也没发生!
我重新启动程序...现在出现新图像...为什么?
当我再次新建 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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)