Changing ImageIcon to another picture with button click

不羁的心 提交于 2019-11-29 11:14:35

Rather then trying to create and add a new label each time, simply call setIcon on the label itself

Something more like...

image = new ImageIcon(imageList[1]);
label.setIcon(image);

Check out How to use lables for more details.

I might also suggest that you load the images first, so you don't need to keep reloading them/creating new objects on each actionPerformed

I'd also recommend ImageIO over ImageIcon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!