Set extent value to JSlider in Java
Description
The following code shows how to set extent value to JSlider.
With extent being set we can only move the slider by a fixed amount of value.
Example
//from w ww .j av a 2 s .c o m
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);
// Set an extent
int extent = 10;
slider.setExtent(extent);
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 »