gpt4 book ai didi

java - ImageIcon 不会更新具有相同 URL 的新图像

转载 作者:行者123 更新时间:2023-12-03 02:04:41 26 4
gpt4 key购买 nike

我想使用 JLabel(Icon) 来显示来 self 的网站 ( 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();

关于java - ImageIcon 不会更新具有相同 URL 的新图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15885696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com