Changing a JLabel's Value from a JSlider's Value

前端 未结 3 1746
Happy的楠姐
Happy的楠姐 2020-12-11 23:26

I have a single JPanel that contains a JSlider and a JLabel. I want to configure it so that when the JSlider\'s value is being changed by the user, that new value is reflect

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 23:43

    What you need to do is add the change listener to the slider.

    Then in the change method that you have to implement, change the value of the text in the JLabel.

    Regarding your code, all the doSomething(int) method needs to do is:

    label.setText(currentTime + "");
    

提交回复
热议问题