Change the maximum value for JSlider in Java
Description
The following code shows how to change the maximum value for JSlider.
Example
//from ww w . j a v a 2 s. c om
import javax.swing.JFrame;
import javax.swing.JSlider;
public class Main {
public static void main(String[] args) {
JFrame f = new JFrame();
int initValue = 20;
int minimum = 10;
int maximum = 100;
JSlider slider = new JSlider(JSlider.VERTICAL, minimum, maximum, initValue);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int newMax = 256;
slider.setMaximum(newMax);
f.add(slider);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »