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
Swing is not thread safe. For more information see Swing's Threading Policy.
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 java..
| Modifier and Type | Class and Description |
|---|---|
| protected class | JSlider.
This class implements accessibility support for the
|
| private class | JSlider.
We pass Change events along to the listeners with the slider (instead of the model itself) as the event source. |
| Modifier and Type | Field and Description |
|---|---|
| protected transient ChangeEvent | changeEvent
Only one |
| protected ChangeListener | changeListener
The changeListener (no suffix) is the listener we add to the slider's model. |
| private boolean | |
| private Dictionary | labelTable
|
| protected int | majorTickSpacing
The number of values between the major tick marks -- the larger marks that break up the minor tick marks. |
| protected int | minorTickSpacing
The number of values between the minor tick marks -- the smaller marks that occur between the major tick marks. |
| protected int | orientation
Whether the slider is horizontal or vertical The default is horizontal. |
| private boolean | |
| private boolean | |
| private boolean | |
| protected BoundedRangeModel | sliderModel
The data model that handles the numeric maximum value, minimum value, and current-position value for the slider. |
| protected boolean | snapToTicks
If true, the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob. |
| pack-priv boolean | snapToValue
If true, the knob (and the data value it represents) resolve to the closest slider value next to where the user positioned the knob. |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JSlider(int
the orientation of the slider orientation)Creates a slider using the specified orientation with the
range |
| public | JSlider(int
the minimum value of the slider min, int the maximum value of the slider max)Creates a horizontal slider using the specified min and max with an initial value equal to the average of the min plus max. |
| public | JSlider(int
the minimum value of the slider min, int the maximum value of the slider max, int the initial value of the slider value)Creates a horizontal slider using the specified min, max and value. |
| public | JSlider(int
the orientation of the slider orientation, int the minimum value of the slider min, int the maximum value of the slider max, int the initial value of the slider value)Creates a slider with the specified orientation and the specified minimum, maximum, and initial values. |
| public | JSlider(BoundedRangeModel
a brm)BoundedRangeModel for the sliderCreates a horizontal slider using the specified BoundedRangeModel. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| private void | |
| protected ChangeListener | Returns: a instance of newChangeListenerSubclasses that want to handle |
| public Hashtable | Returns: a newHashtable of labelsdistance between labels in the generated hashtable increment)Creates a |
| public Hashtable | Returns: a newHashtable of labelsdistance between labels in the generated hashtable increment, int value at which the labels will begin start)Creates a |
| protected void | fireStateChanged()
Send a |
| public AccessibleContext | Returns: an AccessibleJSlider that serves as the AccessibleContext of this JSliderOverrides java. Implements javax. Gets the AccessibleContext associated with this JSlider. |
| public ChangeListener[] | Returns: all of theChangeListeners added or an empty
array if no listeners have been addedReturns an array of all the |
| public int | |
| public boolean | Returns: true if the slider values are reversed from their normal orderReturns true if the value-range shown for the slider is reversed, |
| public Dictionary | Returns: theDictionary containing labels and
where to draw themReturns the dictionary of what labels to draw at which values. |
| public int | Returns: the number of values between major ticksThis method returns the major tick spacing. |
| public int | Returns: the value of the model's maximum propertyReturns the maximum value supported by the slider
from the |
| public int | Returns: the value of the model's minimum propertyReturns the minimum value supported by the slider
from the |
| public int | Returns: the number of values between minor ticksThis method returns the minor tick spacing. |
| public BoundedRangeModel | Returns: the data model for this componentReturns the |
| public int | Returns: SwingConstants.VERTICAL or
SwingConstants.HORIZONTALReturn this slider's vertical or horizontal orientation. |
| public boolean | |
| public boolean | Returns: true if tick marks are painted, else falseTells if tick marks are to be painted. |
| public boolean | Returns: true if track is painted, else falseTells if the track (area the slider slides in) is to be painted. |
| public boolean | Returns: true if the value snaps to the nearest tick mark, else falseReturns true if the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob. |
| pack-priv boolean | Returns: true if the value snaps to the nearest slider value, else falseReturns true if the knob (and the data value it represents) resolve to the closest slider value next to where the user positioned the knob. |
| public SliderUI | Returns: the SliderUI object that implements the Slider L&FOverrides javax. Gets the UI object which implements the L&F for this component. |
| public String | Returns: the string "SliderUI"Overrides javax. Returns the name of the L&F class that renders this component. |
| public int | Returns: the current value of the sliderReturns the slider's current value
from the |
| public boolean | Returns: the value of the model'svalueIsAdjusting propertyReturns the |
| public boolean | imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
Overrides java. Implements java. Repaints the component when the image has changed. |
| protected String | Returns: a string representation of this JSlider.Overrides javax. Returns a string representation of this JSlider. |
| public void | removeChangeListener(ChangeListener
the ChangeListener to remove l)Removes a ChangeListener from the slider. |
| public void | |
| public void | |
| public void | setInverted(boolean
true to reverse the slider values from their normal order b)Specify true to reverse the value-range shown for the slider and false to put the value range in the normal order. |
| public void | setLabelTable(Dictionary<K, V>
new labels)Dictionary of labels, or null to
remove all labelsUsed to specify what label will be drawn at any given value. |
| public void | setMajorTickSpacing(int
new value for the n)majorTickSpacing propertyThis method sets the major tick spacing. |
| public void | |
| public void | |
| public void | setMinorTickSpacing(int
new value for the n)minorTickSpacing propertyThis method sets the minor tick spacing. |
| public void | setModel(BoundedRangeModel
the new, newModel)non-null BoundedRangeModel to useSets the |
| public void | setOrientation(int
HORIZONTAL or VERTICALSet the slider's orientation to either |
| public void | setPaintLabels(boolean
whether or not to paint labels b)Determines whether labels are painted on the slider. |
| public void | setPaintTicks(boolean
whether or not tick marks should be painted b)Determines whether tick marks are painted on the slider. |
| public void | setPaintTrack(boolean
whether or not to paint the slider track b)Determines whether the track is painted on the slider. |
| public void | setSnapToTicks(boolean
true to snap the knob to the nearest tick mark b)Specifying true makes the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob. |
| pack-priv void | setSnapToValue(boolean
true to snap the knob to the nearest slider value b)Specifying true makes the knob (and the data value it represents) resolve to the closest slider value next to where the user positioned the knob. |
| public void | |
| public void | |
| public void | setValueIsAdjusting(boolean
the new value for the b)valueIsAdjusting propertySets the model's |
| private void | |
| protected void | updateLabelUIs()
Updates the UIs for the labels in the label table by calling
|
| public void | updateUI()
Overrides javax. Resets the UI property to a value from the current look and feel. |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See readObject() and writeObject() in JComponent for more information about serialization in Swing. |