Create a JSlider and set min/max value in Java
Description
The following code shows how to create a JSlider and set min/max value.
Example
/*from w w w. ja va 2 s.c o m*/
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Main {
public static void main(String[] args) {
JFrame f = new JFrame();
final JSlider slider = new JSlider(0, 150, 0);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
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 »