javaswingjslider

How to display number selected while sliding JSlide


I'm trying to make a JSlider object show it's value while you are dragging it for this bit of program:

    JPanel sliders = new JPanel(new GridLayout(3,1));
    JSlider jslExtR = new JSlider(JSlider.HORIZONTAL,-255,255,0);
    jslExtR.setMajorTickSpacing(10);
    jslExtR.setMinorTickSpacing(1);
    sliders.add(jslExtR);

I've found some information in the link down here, but it seemed to complicated and thought there had to be an easier way to do it.

http://www.java2s.com/Tutorials/Java/Swing_How_to/JSlider/Show_JSlider_value_while_dragging.htm

Any help or ideas would be really appreciated, thank you.

PS: I DID look on Stack Overflow but no answer asked my question.


Solution

  • I'm trying to make a JSlider object show it's value while you are dragging

    You would use a ChangeListener.

    Read the section from the Swing tutorial on How to Use Sliders for a basic example to get you started.

    Keep a link to the Swing tutorial handy for tutorials on all Swing basics.