A component that lets the user graphically select a value by sliding
a knob within a bounded interval. The knob is always positioned
at the points that match integer values within the specified interval.

The slider can show both
major tick marks, and minor tick marks between the major ones. The number of
values between the tick marks is controlled with
setMajorTickSpacing and setMinorTickSpacing.
Painting of tick marks is controlled by setPaintTicks.

Sliders can also print text labels at regular intervals (or at
arbitrary locations) along the slider track. Painting of labels is
controlled by setLabelTable and setPaintLabels.

For further information and examples see
How to Use Sliders,
a section in The Java Tutorial.

Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans™
has been added to the java.beans package.
Please see XMLEncoder.

orientation

changeListener

The changeListener (no suffix) is the listener we add to the
slider's model. This listener is initialized to the
ChangeListener returned from createChangeListener,
which by default just forwards events
to ChangeListeners (if any) added directly to the slider.

changeEvent

Only one ChangeEvent is needed per slider instance since the
event's only (read-only) state is the source property. The source
of events generated here is always "this". The event is lazily
created the first time that an event notification is fired.

JSlider

public JSlider(int min,
int max)

Creates a horizontal slider using the specified min and max
with an initial value equal to the average of the min plus max.

The BoundedRangeModel that holds the slider's data
handles any issues that may arise from improperly setting the
minimum and maximum values on the slider. See the
BoundedRangeModel documentation for details.

JSlider

public JSlider(int min,
int max,
int value)

Creates a horizontal slider using the specified min, max and value.

The BoundedRangeModel that holds the slider's data
handles any issues that may arise from improperly setting the
minimum, initial, and maximum values on the slider. See the
BoundedRangeModel documentation for details.

JSlider

Creates a slider with the specified orientation and the
specified minimum, maximum, and initial values.
The orientation can be
either SwingConstants.VERTICAL or
SwingConstants.HORIZONTAL.

The BoundedRangeModel that holds the slider's data
handles any issues that may arise from improperly setting the
minimum, initial, and maximum values on the slider. See the
BoundedRangeModel documentation for details.

createChangeListener

Subclasses that want to handle ChangeEvents
from the model differently
can override this to return
an instance of a custom ChangeListener implementation.
The default ChangeListener simply calls the
fireStateChanged method to forward ChangeEvents
to the ChangeListeners that have been added directly to the
slider.

setExtent

public void setExtent(int extent)

Sets the size of the range "covered" by the knob. Most look
and feel implementations will change the value by this amount
if the user clicks on either side of the knob. This method just
forwards the new extent value to the model.

The data model (an instance of BoundedRangeModel)
handles any mathematical
issues arising from assigning faulty values. See the
BoundedRangeModel documentation for details.

If the new extent value is different from the previous extent value,
all change listeners are notified.

imageUpdate

Repaints the component when the image has changed.
This imageUpdate method of an ImageObserver
is called when more information about an
image which had been previously requested using an asynchronous
routine such as the drawImage method of
Graphics becomes available.
See the definition of imageUpdate for
more information on this method and its arguments.

The imageUpdate method of Component
incrementally draws an image on the component as more of the bits
of the image are available.

If the system property awt.image.incrementaldraw
is missing or has the value true, the image is
incrementally drawn. If the system property has any other value,
then the image is not drawn until it has been completely loaded.

Also, if incremental drawing is in effect, the value of the
system property awt.image.redrawrate is interpreted
as an integer to give the maximum redraw rate, in milliseconds. If
the system property is missing or cannot be interpreted as an
integer, the redraw rate is once every 100ms.

The interpretation of the x, y,
width, and height arguments depends on
the value of the infoflags argument.

createStandardLabels

Creates a Hashtable of numerical text labels, starting at the
slider minimum, and using the increment specified.
For example, if you call createStandardLabels( 10 )
and the slider minimum is zero,
then labels will be created for the values 0, 10, 20, 30, and so on.

For the labels to be drawn on the slider, the returned Hashtable
must be passed into setLabelTable, and setPaintLabels
must be set to true.

For further details on the makeup of the returned Hashtable, see
the setLabelTable documentation.

createStandardLabels

Creates a Hashtable of numerical text labels, starting at the
starting point specified, and using the increment specified.
For example, if you call
createStandardLabels( 10, 2 ),
then labels will be created for the values 2, 12, 22, 32, and so on.

For the labels to be drawn on the slider, the returned Hashtable
must be passed into setLabelTable, and setPaintLabels
must be set to true.

For further details on the makeup of the returned Hashtable, see
the setLabelTable documentation.

getInverted

setInverted

public void setInverted(boolean b)

Specify true to reverse the value-range shown for the slider and false to
put the value range in the normal order. The order depends on the
slider's ComponentOrientation property. Normal (non-inverted)
horizontal sliders with a ComponentOrientation value of
LEFT_TO_RIGHT have their maximum on the right.
Normal horizontal sliders with a ComponentOrientation value of
RIGHT_TO_LEFT have their maximum on the left. Normal vertical
sliders have their maximum on the top. These labels are reversed when the
slider is inverted.

By default, the value of this property is false.

Parameters:

b - true to reverse the slider values from their normal order

getMajorTickSpacing

public int getMajorTickSpacing()

This method returns the major tick spacing. The number that is returned
represents the distance, measured in values, between each major tick mark.
If you have a slider with a range from 0 to 50 and the major tick spacing
is set to 10, you will get major ticks next to the following values:
0, 10, 20, 30, 40, 50.

setMajorTickSpacing

public void setMajorTickSpacing(int n)

This method sets the major tick spacing. The number that is passed in
represents the distance, measured in values, between each major tick mark.
If you have a slider with a range from 0 to 50 and the major tick spacing
is set to 10, you will get major ticks next to the following values:
0, 10, 20, 30, 40, 50.

In order for major ticks to be painted, setPaintTicks must be
set to true.

This method will also set up a label table for you.
If there is not already a label table, and the major tick spacing is
> 0, and getPaintLabels returns
true, a standard label table will be generated (by calling
createStandardLabels) with labels at the major tick marks.
For the example above, you would get text labels: "0",
"10", "20", "30", "40", "50".
The label table is then set on the slider by calling
setLabelTable.

getMinorTickSpacing

public int getMinorTickSpacing()

This method returns the minor tick spacing. The number that is returned
represents the distance, measured in values, between each minor tick mark.
If you have a slider with a range from 0 to 50 and the minor tick spacing
is set to 10, you will get minor ticks next to the following values:
0, 10, 20, 30, 40, 50.

setMinorTickSpacing

public void setMinorTickSpacing(int n)

This method sets the minor tick spacing. The number that is passed in
represents the distance, measured in values, between each minor tick mark.
If you have a slider with a range from 0 to 50 and the minor tick spacing
is set to 10, you will get minor ticks next to the following values:
0, 10, 20, 30, 40, 50.

In order for minor ticks to be painted, setPaintTicks must be
set to true.

getPaintLabels

setPaintLabels

public void setPaintLabels(boolean b)

Determines whether labels are painted on the slider.

This method will also set up a label table for you.
If there is not already a label table, and the major tick spacing is
> 0,
a standard label table will be generated (by calling
createStandardLabels) with labels at the major tick marks.
The label table is then set on the slider by calling
setLabelTable.

paramString

Returns a string representation of this JSlider. This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null.