Since you are replacing the shortcut, you need to remove() component and validate() Container . Alternatively, just replace the icon.
Addendum: I think the latter approach is preferable. Without losing the image and the remaining code, start with this: initialize the shortcut and slider:
final JLabel label = new JLabel(pig); final JSlider slider = new JSlider();
Then in the listener use setIcon() :
@Override public void stateChanged(ChangeEvent e) { if (slider.getValue() < 50) { label.setIcon(pig); } else { label.setIcon(dog); } }
source share