Try to understand this code, here I use the icon to set the tag image and the getIcon method for the Tag to change the icon of the previous tag using the setIcon method.
Icon picLabelicon new ImageIcon(img); JLabel picLabel = new JLabel(); picLabel.setIcon(picLabelicon);
Now you have set the icon initially, now let's change it dynamically
JLabel modify = new JLabel(new ImageIcon(newimg)); picLabelicon=modify.getIcon(); picLabel.setIcon(picLabelicon); revalidate(); repaint();
source share