You are on page 1of 8

Sliders

a slider is a component that lets a user


pick a value from a set range (say, from 0
to 50) by moving a knob.
Sliders are a convenient way to get
numeric input from the user when the input
falls within a set range of values.


JSlider Constructors and Methods
To create a slider control, you use the
JSlider class
JSlider() -Creates a new slider. The min
and max values default to 0 and 100, and
the initial value is set to 50.
JSlider(int min, int max) -Creates a new
slider with the specified minimum and
maximum values. The initial value is
halfway between min and max.
JSlider(int min, int max, int value) -Creates
a new slider with the specified minimum,
maximum, and initial values.
JSlider(int orientation, int max, int value) -
Creates a new slider with the specified
minimum, maximum, and initial values.
The orientation can be either
JSlider.HORIZONTAL or
JSlider.VERTICAL. int min,
Methods
void addChangeListener (ChangeListener
listener) Adds a ChangeListener to listen
for change events
int getValue() Gets the value indicated by
the current position of the knob.
void setFont() Sets the font of the text
associated with the slider.
void setInvert (boolean value) If true, inverts the
slider's direction so the max value is on the left
and the min value is on the right
void setMajorTickSpacing (int value) Sets the
interval for major tick marks. The marks aren't
shown unless setPaintTicks(true) is called.
void setMinimum(int value) Sets the minimum
value.
void setMaximum(int value) Sets the maximum
value.
void setMinorTickSpacing (int value) Sets the
interval for minor tick marks. The marks aren't
shown unless setPaintTicks(true) is called.
setOrientation (int orientation) Sets the
orientation. Allowed values are
JSlider.HORIZONTAL and JSlider.VERTICAL.

You might also like