Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JSlider
public class JSlider
extends JComponent
implements SwingConstants, Accessible, ImageObserver, MenuContainer, Serializable
DefaultBoundedRangeModel
.
A JSlider
component has the following properties:
Property | Stored in | Bound? |
---|---|---|
extent | model | no |
inverted | slider | yes |
labelTable | slider | yes |
majorTickSpacing | slider | yes |
maximum | model | yes |
minimum | model | yes |
minorTickSpacing | slider | yes |
model | slider | yes |
orientation | slider | yes |
paintLabels | slider | yes |
paintTicks | slider | yes |
snapToTicks | slider | yes |
value | model | no |
valueIsAdjusting | model | no |
ChangeEvent
to its change listeners.
PropertyChangeEvent
to its property change listeners.
ChangeEvent
to
its listeners, which include the slider.
ChangeEvent
from its model, it will
propagate the event to its own change listeners, with the event's "source"
property set to refer to the slider, rather than the model.
Nested Class Summary | |
protected class |
|
Nested classes/interfaces inherited from class javax.swing.JComponent | |
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container | |
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component | |
Component.AccessibleAWTComponent , Component.BltBufferStrategy , Component.FlipBufferStrategy |
Field Summary | |
protected ChangeEvent |
|
protected ChangeListener |
|
protected int |
|
protected int |
|
protected int |
|
protected BoundedRangeModel |
|
protected boolean |
|
Fields inherited from class javax.swing.JComponent | |
TOOL_TIP_TEXT_KEY , UNDEFINED_CONDITION , WHEN_ANCESTOR_OF_FOCUSED_COMPONENT , WHEN_FOCUSED , WHEN_IN_FOCUSED_WINDOW , accessibleContext , listenerList , ui |
Fields inherited from class java.awt.Component | |
BOTTOM_ALIGNMENT , CENTER_ALIGNMENT , LEFT_ALIGNMENT , RIGHT_ALIGNMENT , TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver | |
ABORT , ALLBITS , ERROR , FRAMEBITS , HEIGHT , PROPERTIES , SOMEBITS , WIDTH |
Fields inherited from interface javax.swing.SwingConstants | |
BOTTOM , CENTER , EAST , HORIZONTAL , LEADING , LEFT , NEXT , NORTH , NORTH_EAST , NORTH_WEST , PREVIOUS , RIGHT , SOUTH , SOUTH_EAST , SOUTH_WEST , TOP , TRAILING , VERTICAL , WEST |
Constructor Summary | |
| |
| |
| |
| |
| |
|
Method Summary | |
void |
|
protected ChangeListener |
|
Hashtable<K,V> |
|
Hashtable<K,V> |
|
protected void |
|
AccessibleContext |
|
ChangeListener[] |
|
int |
|
boolean |
|
Dictionary<K,V> |
|
int |
|
int |
|
int |
|
int |
|
BoundedRangeModel |
|
int |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
SliderUI |
|
String |
|
int |
|
boolean |
|
protected String |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
protected void |
|
void |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
protected ChangeEvent changeEvent
The change event that is passed to all listeners of this slider.
protected ChangeListener changeListener
The listener that monitors the slider's model and forwards events to the slider's listeners (seecreateChangeListener()
).
protected BoundedRangeModel sliderModel
The model used to store the slider's range and current value.
public JSlider()
Creates a new horizontalJSlider
instance with a minimum of 0, a maximum of 100, and a value of 50.
public JSlider(int orientation)
Creates a newJSlider
instance with the given orientation and a minimum of 0, a maximum of 100, and a value of 50.
- Parameters:
orientation
- The orientation of the slider (SwingConstants.HORIZONTAL
orSwingConstants.VERTICAL
).
- Throws:
IllegalArgumentException
- iforientation
is not one of the specified values.
public JSlider(int minimum, int maximum)
Creates a new horizontalJSlider
instance with the given maximum and minimum and a value that is halfway between the minimum and the maximum.
- Parameters:
minimum
- The minimum value.maximum
- The maximum value.
- Throws:
IllegalArgumentException
- ifminimum
is greater thanmaximum
.
public JSlider(int minimum, int maximum, int value)
Creates a new horizontalJSlider
instance with the given minimum, maximum, and value.
- Parameters:
minimum
- The minimum value.maximum
- The maximum value.value
- The initial value.
- Throws:
IllegalArgumentException
- ifvalue
is not in the specified range.IllegalArgumentException
- ifminimum
is greater thanmaximum
.
public JSlider(int orientation, int minimum, int maximum, int value)
Creates a newJSlider
instance with the given orientation, minimum, maximum, and value.
- Parameters:
orientation
- The orientation of the slider (SwingConstants.HORIZONTAL
orSwingConstants.VERTICAL
).minimum
- The minimum value of the JSlider.maximum
- The maximum value of the JSlider.value
- The initial value of the JSlider.
- Throws:
IllegalArgumentException
- iforientation
is not one of the specified values.IllegalArgumentException
- ifvalue
is not in the specified range.IllegalArgumentException
- ifminimum
is greater thanmaximum
.
public JSlider(BoundedRangeModel model)
Creates a new horizontalJSlider
instance with the given model.
- Parameters:
model
- The model (null
not permitted).
- Throws:
NullPointerException
- ifmodel
isnull
.
public void addChangeListener(ChangeListener listener)
Registers a listener with the slider so that it will receiveChangeEvent
notifications. Note that change events generated by the slider's model will be forwarded automatically to the slider's listeners.
- Parameters:
listener
- the listener to register.
- See Also:
removeChangeListener(ChangeListener)
protected ChangeListener createChangeListener()
Creates aChangeListener
that is added to the slider's model and forwards change events generated by the model to the listeners that are registered with theJSlider
(by calling thefireStateChanged()
method).
- Returns:
- A new listener.
public Hashtable<K,V> createStandardLabels(int increment)
Creates a hashtable of(Integer, JLabel)
pairs that can be used as a label table for this slider. The labels will start from the slider's minimum and increase by the increment. Each label will have a text string indicating its integer value.
- Parameters:
increment
- The increment between labels (must be > 0).
- Returns:
- A hashtable containing the labels.
- Throws:
IllegalArgumentException
- ifincrement
is not greater than zero.
public Hashtable<K,V> createStandardLabels(int increment, int start)
Creates a hashtable of(Integer, JLabel)
pairs that can be used as a label table for this slider. The labels will start from the given start value and increase by the increment. Each label will have a text string indicating its integer value.
- Parameters:
increment
- The increment between labels (must be > 0).start
- The value to start from.
- Returns:
- A hashtable with the labels and their keys.
- Throws:
IllegalArgumentException
- ifincrement
is not greater than zero, orstart
is not within the range of the model.
protected void fireStateChanged()
Sends aChangeEvent
to all registered listeners, with this slider as the source.
public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for thisJSlider
component.
- Specified by:
- getAccessibleContext in interface Accessible
- Overrides:
- getAccessibleContext in interface JComponent
- Returns:
- The accessible context (an instance of
JSlider.AccessibleJSlider
).
public ChangeListener[] getChangeListeners()
Returns an array containing all theChangeListener
instances registered with this slider. If no listeners are registered, this method returns an empty array.
- Returns:
- An array array containing all the
ChangeListener
instances registered with this slider (possibly empty, but nevernull
).
public int getExtent()
Returns the slider's extent value, obtained from the slider's model.
- Returns:
- The extent value.
- See Also:
setExtent(int)
public boolean getInverted()
Returns the flag that controls whether or not the value scale for the slider is inverted (the default value isfalse
).
- Returns:
- The flag that controls whether or not the value scale for the slider is inverted.
- See Also:
setInverted(boolean)
public Dictionary<K,V> getLabelTable()
Returns the label table for the slider.
- Returns:
- The label table for the slider (possibly
null
).
- See Also:
setLabelTable(Dictionary)
public int getMajorTickSpacing()
Returns the distance between major tick marks along the slider's value scale.
- Returns:
- The amount of units between each major tick mark.
- See Also:
setMajorTickSpacing(int)
public int getMaximum()
Returns the slider's maximum value (obtained from the slider's model).
- Returns:
- The maximum value of the slider.
- See Also:
setMaximum(int)
public int getMinimum()
Returns the minimum value of the slider (from the slider's model).
- Returns:
- The minimum value of the slider.
- See Also:
setMinimum(int)
public int getMinorTickSpacing()
Returns the distance between minor tick marks along the slider's value scale.
- Returns:
- The distance between minor tick marks along the slider's value scale.
- See Also:
setMinorTickSpacing(int)
public BoundedRangeModel getModel()
Returns the slider's model, which stores the minimum, maximum and current values.
- Returns:
- The slider's model.
- See Also:
setModel(BoundedRangeModel)
public int getOrientation()
Returns the orientation of the slider, eitherSwingConstants.HORIZONTAL
orSwingConstants.VERTICAL
.
- Returns:
- The orientation of the slider.
- See Also:
setOrientation(int)
public boolean getPaintLabels()
Returns the flag that controls whether or not labels are painted for the tick marks along the slider.
- Returns:
- Whether labels will be painted.
- See Also:
setPaintLabels(boolean)
public boolean getPaintTicks()
Returns the flag that controls whether or not tick marks are painted along the slider's value scale.
- Returns:
true
if tick marks should be painted, andfalse
if tick marks should not be painted.
- See Also:
setPaintTicks(boolean)
public boolean getPaintTrack()
Returns the flag that controls whether or not the track is painted.
- Returns:
- Whether the track will be painted.
- See Also:
setPaintTrack(boolean)
public boolean getSnapToTicks()
Returns the flag that controls whether the slider thumb will snap to ticks. Sliders that snap to ticks will automatically move the thumb to the nearest tick mark.
- Returns:
true
if the slider thumb automatically.
- See Also:
setSnapToTicks(boolean)
public String getUIClassID()
Returns the suffix ("SliderUI"
in this case) used to determine the class name for a UI delegate that can provide the look and feel for aJSlider
.
- Overrides:
- getUIClassID in interface JComponent
- Returns:
"SliderUI"
.
public int getValue()
Returns the slider's value (from the slider's model).
- Returns:
- The value of the slider.
- See Also:
setValue(int)
public boolean getValueIsAdjusting()
Returns thevalueIsAdjusting
flag from the slider's model.
- Returns:
- The
valueIsAdjusting
flag from the slider's model.
- See Also:
setValueIsAdjusting(boolean)
protected String paramString()
Returns an implementation-dependent string describing the attributes of thisJSlider
.
- Overrides:
- paramString in interface JComponent
- Returns:
- A string describing the attributes of this
JSlider
(nevernull
).
public void removeChangeListener(ChangeListener listener)
Removes a listener from this slider so that it will no longer receiveChangeEvent
notifications from the slider.
- Parameters:
listener
- The listener to remove.
- See Also:
addChangeListener(ChangeListener)
public void setExtent(int extent)
Sets the slider's extent value and sends aChangeEvent
to all registered listeners. Note that the model will fire a change event to all of its registered listeners first (with the model as the event source) and then the slider will fire another change event to all of its registered listeners (this time with the slider as the event source).
- Parameters:
extent
- The extent value for this slider.
- See Also:
getExtent()
public void setInverted(boolean inverted)
Sets the flag that controls whether or not the value scale for the slider is inverted and, if the new flag value is different to the old flag value, sends aPropertyChangeEvent
to all registered listeners. Typically, a horizontal slider will display a scale that increases from left to right, but this is reversed if the 'inverted' flag is set totrue
. Similarly, a vertical slider will display a scale that increases from bottom to top, and this is reversed if the 'inverted' flag is set totrue
.
- Parameters:
inverted
- the new flag value.
- See Also:
getInverted()
public void setLabelTable(Dictionary<K,V> table)
Sets the table of labels for the slider and sends aPropertyChangeEvent
(with the property name "labelTable") to all registered listeners.
- Parameters:
table
- the table of labels (null
permitted).
- See Also:
getLabelTable()
public void setMajorTickSpacing(int spacing)
Sets the distance between major tick marks along the slider's value scale, and sends aPropertyChangeEvent
(with the property name "majorTickSpacing") to all registered listeners.
- Parameters:
spacing
- the distance between major tick marks.
- See Also:
getMajorTickSpacing()
public void setMaximum(int maximum)
Sets the maximum value of the slider and fires aPropertyChangeEvent
(with the property name "maximum") to all registered listeners. Note that:
- the maximum value is stored in the slider's model (see
getModel()
);- in addition to the property change event, the slider also fires a
ChangeEvent
.
- Parameters:
maximum
- The maximum value of the slider.
- See Also:
getMaximum()
public void setMinimum(int minimum)
Sets the minimum value of the slider and fires aPropertyChangeEvent
(with the property name "minimum") to all registered listeners. Note that:
- the minimum value is stored in the slider's model (see
getModel()
);- in addition to the property change event, the slider also fires a
ChangeEvent
.
- Parameters:
minimum
- The minimum value of the slider.
- See Also:
getMinimum()
public void setMinorTickSpacing(int spacing)
Sets the distance between minor tick marks along the slider's value scale, and sends aPropertyChangeEvent
(with the property name "minorTickSpacing") to all registered listeners.
- Parameters:
spacing
- the distance between minor tick marks.
- See Also:
getMinorTickSpacing()
public void setModel(BoundedRangeModel model)
Sets the slider's model and sends aPropertyChangeEvent
(with the property name "model") to all registered listeners. The change listener that the slider registered with the original model is removed and added to the new model (this ensures thatChangeEvent
notifications generated by the model are automatically forwarded to listeners that are registered with the slider).
- Parameters:
model
- The model to use with the slider.
- See Also:
getModel()
public void setOrientation(int orientation)
Sets the orientation for the slider and sends aPropertyChangeEvent
(with the property name "orientation") to all registered listeners.
- Parameters:
orientation
- the orientation (one ofSwingConstants.HORIZONTAL
orSwingConstants.VERTICAL
).
- Throws:
IllegalArgumentException
- iforientation
is not one of the permitted values.
- See Also:
getOrientation()
public void setPaintLabels(boolean paint)
Sets the flag that controls whether or not labels are painted for the tick marks along the slider and sends aPropertyChangeEvent
(with the property name "paintLabels") to all registered listeners.
- Parameters:
paint
- Whether labels will be painted.
- See Also:
getPaintLabels()
public void setPaintTicks(boolean paint)
Sets the flag that controls whether or not tick marks are painted along the slider's value scale, and sends aPropertyChangeEvent
(with the property name "paintTicks") to all registered listeners. In addition to setting this property totrue
, one or both of the minor tick spacing and major tick spacing attributes must be set to a value greater than 0 in order for ticks to be painted.
- Parameters:
paint
- Whether ticks will be painted.
- See Also:
getPaintTicks()
public void setPaintTrack(boolean paint)
Sets the flag that controls whether or not the track is painted, and sends aPropertyChangeEvent
(for the "paintTrack" property) to all registered listeners.
- Parameters:
paint
- Whether the track will be painted.
- See Also:
getPaintTrack()
public void setSnapToTicks(boolean snap)
Sets the flag that controls whether the slider thumb will snap to ticks and sends aPropertyChangeEvent
(with the property name 'snapToTicks') to all registered listeners. Sliders that snap to ticks will automatically move the thumb to the nearest tick mark.
- Parameters:
snap
- the new flag value.
- See Also:
getSnapToTicks()
public void setValue(int value)
Sets the slider's value and sends aChangeEvent
to all registered listeners. Note that the model will fire a change event to all of its registered listeners first (with the model as the event source) and then the slider will fire another change event to all of its registered listeners (this time with the slider as the event source).
- Parameters:
value
- the new value.
- See Also:
getValue()
public void setValueIsAdjusting(boolean adjusting)
Sets thevalueIsAdjusting
flag in the slider's model, and sends aChangeEvent
to all registered listeners.
- Parameters:
adjusting
- the new flag value.
- See Also:
getValueIsAdjusting()
protected void updateLabelUIs()
Resets the UI delegates for the labels in thelabelTable
to the default for the current look and feel.
public void updateUI()
Sets this slider's UI delegate to the default (obtained from theUIManager
) for the current look and feel.
- Overrides:
- updateUI in interface JComponent