【发布时间】:2013-03-11 08:38:27
【问题描述】:
我正在使用以下类将背景图像添加到 JPanel。
http://www.java2s.com/Code/Java/Swing-JFC/Panelwithbackgroundimage.htm
但是当应用程序正在执行并更改图像时,新的更新图像不会显示在屏幕上。
Image image = new ImageIcon(path + item.getItemID() + ".png").getImage();
panel = new ImagePanel(image);
变量路径是工作区外的静态路径。
【问题讨论】:
-
在图像更改后尝试
panel.repaint()。还有,怎么换头像?你在创建一个新的 ImagePanel 吗? -
对此进行了尝试,也尝试使用新的 JPanel 更新 JPanel。但得到相同的旧图像。在油漆中手动更改图像
-
此外,如果从路径中删除图像,应用程序会将图像显示到 JPanel 背景
标签: java image swing jpanel paintcomponent