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

前端 未结 3 1740
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:52

    You don't listen for ChangeEvents on a JLabel. You listen for ChangeEvents on the JSlider and then in the stateChanged() method you simply use

    label.setText("Time: " + scaleSlider.getValue());
    

    No need to fire any event from the ChangeLisetner either.

提交回复
热议问题