Image cannot update other components (MVC)

import java.awt.event.ActionListener; import java.util.*; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.ActionEvent; import java.awt.event.AdjustmentListener; import java.awt.event.AdjustmentEvent; 

I have several other frames (two are just punching numbers, and the other is also a scrollbar). I can use other components to update this view (this basically displays the image window based on the temperature scale). Similarly, I can update other components from this view.

However (edited), the panel moves, but the image remains the same .... Can someone see the error? I appreciate any contributions to this / Thank you!

+1
source share
1 answer

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); } } 
+2
source

Source: https://habr.com/ru/post/1433098/


All Articles