javaswinguser-interfacejslider

Changing the unit movement of a JSlider


I suppose this is a very silly question but I cannot figure out the solution/how to ask this to google. Basically, I want that my JSlider changes every X units each time an user clicks on it instead of 1 unit. How can I do it?


Solution

  • that's what I did in one of my apps... suppose it was setMinorTickSpacing()and setMajorTickSpacing():

    JSlider jSlider1 = new JSlider();
    jSlider1.setMajorTickSpacing(50);
    jSlider1.setMaximum(500);
    jSlider1.setMinimum(100);
    jSlider1.setMinorTickSpacing(50);
    jSlider1.setPaintLabels(true);
    jSlider1.setPaintTicks(true);
    jSlider1.setSnapToTicks(true);