I have one JPanel that contains JSlider and JLabel. I want to configure it so that when the JSlider value is changed by the user, this new value is reflected in JLabel.
I understand that I can run ChangeEvents using Slider, but I donβt know how to add ChangeListener to JLabel. Here is a snippet of my code.
scaleSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent event)
{
int currentTime = ((JSlider)event.getSource()).getValue();
doSomething(currentTime);
fireStateChanged(event);
}
JLabel timeValue = new JLabel("Time: " + scaleSlider.getValue());
timeValue.add???
(I do not know what to do now to reflect the changes in the slider)
Am I going in the right direction with this? Thanks in advance for your help.
source
share