|
|||||||||
| Home >> All >> javax >> [ swing overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
javax.swing
Class JSlider

java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JSlider
- All Implemented Interfaces:
- javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, SwingConstants
- public class JSlider
- extends JComponent
- implements SwingConstants, javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
- extends JComponent
A visual component that allows selection of a value within a range by adjusting a thumb in a track. The values for the minimum, maximum, extent and value are stored in a 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 |
The various behavioural aspects of these properties follows:
- When a non-bound property stored in the slider changes, the slider fires a javax.swing.event.ChangeEvent to its change listeners.
- When a bound property stored in the slider changes, the slider fires a java.beans.PropertyChangeEvent to its property change listeners.
- If any of the model's properties change, it fires a javax.swing.event.ChangeEvent to its listeners, which include the slider.
- If the slider receives a javax.swing.event.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 |
JSlider.AccessibleJSlider
Provides the accessibility features for the JSlider
component. |
| Nested classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary | |
protected javax.swing.event.ChangeEvent |
changeEvent
The change event that is passed to all listeners of this slider. |
protected javax.swing.event.ChangeListener |
changeListener
The listener that monitors the slider's model and forwards events to the slider's listeners (see createChangeListener()). |
private boolean |
isInverted
Whether the slider is inverted. |
private java.util.Dictionary |
labelTable
A dictionary of (Integer, Component) pairs where each Component is a JLabel and the Integer determines where the label will be painted. |
protected int |
majorTickSpacing
The space/distance between major ticks. |
protected int |
minorTickSpacing
The space/distance between minor ticks. |
protected int |
orientation
The orientation (horizontal or vertical) of the slider. |
private boolean |
paintLabels
Whether or not this slider paints its labels. |
private boolean |
paintTicks
Whether or not this slider paints its ticks. |
private boolean |
paintTrack
Whether or not this slider paints its track. |
private static long |
serialVersionUID
|
protected BoundedRangeModel |
sliderModel
The model used to store the slider's range and current value. |
protected boolean |
snapToTicks
Whether the slider snaps its values to ticks. |
| Fields inherited from class javax.swing.JComponent |
accessibleContext, alignmentX, alignmentY, autoscrolls, border, debugGraphicsOptions, doubleBuffered, isCompletelyDirty, isPaintingDoubleBuffered, listenerList, maximumSize, minimumSize, opaque, preferredSize, requestFocusEnabled, TOOL_TIP_TEXT_KEY, toolTipText, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Container |
|
| Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| 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 |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
JSlider()
Creates a new horizontal JSlider instance with a minimum of
0, a maximum of 100, and a value of 50. |
|
JSlider(BoundedRangeModel model)
Creates a new horizontal JSlider instance with the given
model. |
|
JSlider(int orientation)
Creates a new JSlider instance with the given orientation
and a minimum of 0, a maximum of 100, and a value of 50. |
|
JSlider(int minimum,
int maximum)
Creates a new horizontal JSlider instance with the given
maximum and minimum and a value that is halfway between the minimum and the
maximum. |
|
JSlider(int minimum,
int maximum,
int value)
Creates a new horizontal JSlider instance with the given
minimum, maximum, and value. |
|
JSlider(int orientation,
int minimum,
int maximum,
int value)
Creates a new JSlider instance with the given orientation,
minimum, maximum, and value. |
|
| Method Summary | |
void |
addChangeListener(javax.swing.event.ChangeListener listener)
Registers a listener with the slider so that it will receive javax.swing.event.ChangeEvent notifications. |
protected javax.swing.event.ChangeListener |
createChangeListener()
Creates a javax.swing.event.ChangeListener that is added to the slider's model and forwards change events generated by the model to the listeners that are registered with the JSlider (by calling the
fireStateChanged() 55 method). |
java.util.Hashtable |
createStandardLabels(int increment)
Creates a hashtable of (Integer, JLabel) pairs that can be
used as a label table for this slider. |
java.util.Hashtable |
createStandardLabels(int increment,
int start)
Creates a hashtable of (Integer, JLabel) pairs that can be
used as a label table for this slider. |
protected void |
fireStateChanged()
Sends a javax.swing.event.ChangeEvent to all registered listeners, with this slider as the source. |
javax.accessibility.AccessibleContext |
getAccessibleContext()
Returns the object that provides accessibility features for this JSlider component. |
javax.swing.event.ChangeListener[] |
getChangeListeners()
Returns an array containing all the javax.swing.event.ChangeListener instances registered with this slider. |
int |
getExtent()
Returns the slider's extent value, obtained from the slider's model. |
boolean |
getInverted()
Returns the flag that controls whether or not the value scale for the slider is inverted (the default value is false). |
java.util.Dictionary |
getLabelTable()
Returns the label table for the slider. |
int |
getMajorTickSpacing()
Returns the distance between major tick marks along the slider's value scale. |
int |
getMaximum()
Returns the slider's maximum value (obtained from the slider's model). |
int |
getMinimum()
Returns the minimum value of the slider (from the slider's model). |
int |
getMinorTickSpacing()
Returns the distance between minor tick marks along the slider's value scale. |
BoundedRangeModel |
getModel()
Returns the slider's model, which stores the minimum, maximum and current values. |
int |
getOrientation()
Returns the orientation of the slider, either SwingConstants.HORIZONTAL 55
or SwingConstants.VERTICAL 55 . |
boolean |
getPaintLabels()
Returns the flag that controls whether or not labels are painted for the tick marks along the slider. |
boolean |
getPaintTicks()
Returns the flag that controls whether or not tick marks are painted along the slider's value scale. |
boolean |
getPaintTrack()
Returns the flag that controls whether or not the track is painted. |
boolean |
getSnapToTicks()
Returns the flag that controls whether the slider thumb will snap to ticks. |
javax.swing.plaf.SliderUI |
getUI()
Returns the slider's UI delegate. |
java.lang.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 a JSlider. |
int |
getValue()
Returns the slider's value (from the slider's model). |
boolean |
getValueIsAdjusting()
Returns the valueIsAdjusting flag from the slider's model. |
protected java.lang.String |
paramString()
Returns an implementation-dependent string describing the attributes of this JSlider. |
void |
removeChangeListener(javax.swing.event.ChangeListener listener)
Removes a listener from this slider so that it will no longer receive javax.swing.event.ChangeEvent notifications from the slider. |
void |
setExtent(int extent)
Sets the slider's extent value and sends a javax.swing.event.ChangeEvent to all registered listeners. |
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 a java.beans.PropertyChangeEvent to all registered listeners. |
void |
setLabelTable(java.util.Dictionary table)
Sets the table of labels for the slider and sends a java.beans.PropertyChangeEvent (with the property name "labelTable") to all registered listeners. |
void |
setMajorTickSpacing(int spacing)
Sets the distance between major tick marks along the slider's value scale, and sends a java.beans.PropertyChangeEvent (with the property name "majorTickSpacing") to all registered listeners. |
void |
setMaximum(int maximum)
Sets the maximum value of the slider and fires a java.beans.PropertyChangeEvent (with the property name "maximum") to all registered listeners. |
void |
setMinimum(int minimum)
Sets the minimum value of the slider and fires a java.beans.PropertyChangeEvent (with the property name "minimum") to all registered listeners. |
void |
setMinorTickSpacing(int spacing)
Sets the distance between minor tick marks along the slider's value scale, and sends a java.beans.PropertyChangeEvent (with the property name "minorTickSpacing") to all registered listeners. |
void |
setModel(BoundedRangeModel model)
Sets the slider's model and sends a java.beans.PropertyChangeEvent (with the property name "model") to all registered listeners. |
void |
setOrientation(int orientation)
Sets the orientation for the slider and sends a java.beans.PropertyChangeEvent (with the property name "orientation") to all registered listeners. |
void |
setPaintLabels(boolean paint)
Sets the flag that controls whether or not labels are painted for the tick marks along the slider and sends a java.beans.PropertyChangeEvent (with the property name "paintLabels") to all registered listeners. |
void |
setPaintTicks(boolean paint)
Sets the flag that controls whether or not tick marks are painted along the slider's value scale, and sends a java.beans.PropertyChangeEvent (with the property name "paintTicks") to all registered listeners. |
void |
setPaintTrack(boolean paint)
Sets the flag that controls whether or not the track is painted, and sends a java.beans.PropertyChangeEvent (for the "paintTrack" property) to all registered listeners. |
void |
setSnapToTicks(boolean snap)
Sets the flag that controls whether the slider thumb will snap to ticks and sends a java.beans.PropertyChangeEvent (with the property name 'snapToTicks') to all registered listeners. |
void |
setUI(javax.swing.plaf.SliderUI ui)
Sets the slider's UI delegate. |
void |
setValue(int value)
Sets the slider's value and sends a javax.swing.event.ChangeEvent to all registered listeners. |
void |
setValueIsAdjusting(boolean adjusting)
Sets the valueIsAdjusting flag in the slider's model, and
sends a javax.swing.event.ChangeEvent to all registered listeners. |
protected void |
updateLabelUIs()
Resets the UI delegates for the labels in the labelTable to
the default for the current look and feel. |
void |
updateUI()
Sets this slider's UI delegate to the default (obtained from the UIManager) for the current look and feel. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.awt.image.ImageObserver |
imageUpdate |
| Methods inherited from interface java.awt.MenuContainer |
getFont, postEvent, remove |
| Field Detail |
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
paintTicks
private transient boolean paintTicks
- Whether or not this slider paints its ticks.
paintTrack
private transient boolean paintTrack
- Whether or not this slider paints its track.
paintLabels
private transient boolean paintLabels
- Whether or not this slider paints its labels.
labelTable
private transient java.util.Dictionary labelTable
- A dictionary of (Integer, Component) pairs where each Component is a
JLabel and the Integer determines where the label will be painted.
sliderModel
protected BoundedRangeModel sliderModel
- The model used to store the slider's range and current value.
majorTickSpacing
protected int majorTickSpacing
- The space/distance between major ticks.
minorTickSpacing
protected int minorTickSpacing
- The space/distance between minor ticks.
snapToTicks
protected boolean snapToTicks
- Whether the slider snaps its values to ticks.
orientation
protected int orientation
- The orientation (horizontal or vertical) of the slider.
isInverted
private transient boolean isInverted
- Whether the slider is inverted.
changeListener
protected javax.swing.event.ChangeListener changeListener
- The listener that monitors the slider's model and forwards events to the
slider's listeners (see
createChangeListener()).
changeEvent
protected transient javax.swing.event.ChangeEvent changeEvent
- The change event that is passed to all listeners of this slider.
| Constructor Detail |
JSlider
public JSlider()
- Creates a new horizontal
JSliderinstance with a minimum of 0, a maximum of 100, and a value of 50.
JSlider
public JSlider(int orientation)
- Creates a new
JSliderinstance with the given orientation and a minimum of 0, a maximum of 100, and a value of 50.
JSlider
public JSlider(int minimum,
int maximum)
- Creates a new horizontal
JSliderinstance with the given maximum and minimum and a value that is halfway between the minimum and the maximum.
JSlider
public JSlider(int minimum,
int maximum,
int value)
- Creates a new horizontal
JSliderinstance with the given minimum, maximum, and value.
JSlider
public JSlider(int orientation,
int minimum,
int maximum,
int value)
- Creates a new
JSliderinstance with the given orientation, minimum, maximum, and value.
JSlider
public JSlider(BoundedRangeModel model)
- Creates a new horizontal
JSliderinstance with the given model.
| Method Detail |
getValue
public int getValue()
- Returns the slider's value (from the slider's model).
setValue
public void setValue(int value)
- Sets the slider's value and sends a javax.swing.event.ChangeEvent 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).
getUI
public javax.swing.plaf.SliderUI getUI()
- Returns the slider's UI delegate.
setUI
public void setUI(javax.swing.plaf.SliderUI ui)
- Sets the slider's UI delegate.
updateUI
public void updateUI()
- Sets this slider's UI delegate to the default (obtained from the
UIManager) for the current look and feel.
- Overrides:
updateUIin classJComponent
getUIClassID
public java.lang.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:
getUIClassIDin classJComponent
createChangeListener
protected javax.swing.event.ChangeListener createChangeListener()
- Creates a javax.swing.event.ChangeListener that is added to the slider's model and
forwards change events generated by the model to the listeners that are
registered with the
JSlider(by calling thefireStateChanged()55 method).
addChangeListener
public void addChangeListener(javax.swing.event.ChangeListener listener)
- Registers a listener with the slider so that it will receive
javax.swing.event.ChangeEvent notifications. Note that change events generated
by the slider's model will be forwarded automatically to the slider's
listeners.
removeChangeListener
public void removeChangeListener(javax.swing.event.ChangeListener listener)
- Removes a listener from this slider so that it will no longer receive
javax.swing.event.ChangeEvent notifications from the slider.
fireStateChanged
protected void fireStateChanged()
- Sends a javax.swing.event.ChangeEvent to all registered listeners, with this slider
as the source.
getChangeListeners
public javax.swing.event.ChangeListener[] getChangeListeners()
- Returns an array containing all the javax.swing.event.ChangeListener instances
registered with this slider. If no listeners are registered, this method
returns an empty array.
getModel
public BoundedRangeModel getModel()
- Returns the slider's model, which stores the minimum, maximum and current
values.
setModel
public void setModel(BoundedRangeModel model)
- Sets the slider's model and sends a java.beans.PropertyChangeEvent (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 that javax.swing.event.ChangeEvent notifications
generated by the model are automatically forwarded to listeners that are
registered with the slider).
getMinimum
public int getMinimum()
- Returns the minimum value of the slider (from the slider's model).
setMinimum
public void setMinimum(int minimum)
- Sets the minimum value of the slider and fires a
java.beans.PropertyChangeEvent (with the property name "minimum") to all
registered listeners. Note that:
- the minimum value is stored in the slider's model (see
getModel()55 ); - in addition to the property change event, the slider also fires a javax.swing.event.ChangeEvent.
- the minimum value is stored in the slider's model (see
getMaximum
public int getMaximum()
- Returns the slider's maximum value (obtained from the slider's model).
setMaximum
public void setMaximum(int maximum)
- Sets the maximum value of the slider and fires a
java.beans.PropertyChangeEvent (with the property name "maximum") to all
registered listeners. Note that:
- the maximum value is stored in the slider's model (see
getModel()55 ); - in addition to the property change event, the slider also fires a javax.swing.event.ChangeEvent.
- the maximum value is stored in the slider's model (see
getValueIsAdjusting
public boolean getValueIsAdjusting()
- Returns the
valueIsAdjustingflag from the slider's model.
setValueIsAdjusting
public void setValueIsAdjusting(boolean adjusting)
- Sets the
valueIsAdjustingflag in the slider's model, and sends a javax.swing.event.ChangeEvent to all registered listeners.
getExtent
public int getExtent()
- Returns the slider's extent value, obtained from the slider's model.
setExtent
public void setExtent(int extent)
- Sets the slider's extent value and sends a javax.swing.event.ChangeEvent 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).
getOrientation
public int getOrientation()
- Returns the orientation of the slider, either
SwingConstants.HORIZONTAL55 orSwingConstants.VERTICAL55 .
setOrientation
public void setOrientation(int orientation)
- Sets the orientation for the slider and sends a
java.beans.PropertyChangeEvent (with the property name "orientation") to all
registered listeners.
getLabelTable
public java.util.Dictionary getLabelTable()
- Returns the label table for the slider.
setLabelTable
public void setLabelTable(java.util.Dictionary table)
- Sets the table of labels for the slider and sends a
java.beans.PropertyChangeEvent (with the property name "labelTable") to all
registered listeners.
updateLabelUIs
protected void updateLabelUIs()
- Resets the UI delegates for the labels in the
labelTableto the default for the current look and feel.
createStandardLabels
public java.util.Hashtable 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.
createStandardLabels
public java.util.Hashtable 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.
getInverted
public boolean getInverted()
- Returns the flag that controls whether or not the value scale for the
slider is inverted (the default value is
false).
setInverted
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 a java.beans.PropertyChangeEvent 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 to
true. 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.
getMajorTickSpacing
public int getMajorTickSpacing()
- Returns the distance between major tick marks along the slider's value
scale.
setMajorTickSpacing
public void setMajorTickSpacing(int spacing)
- Sets the distance between major tick marks along the slider's value scale,
and sends a java.beans.PropertyChangeEvent (with the property name
"majorTickSpacing") to all registered listeners.
getMinorTickSpacing
public int getMinorTickSpacing()
- Returns the distance between minor tick marks along the slider's value
scale.
setMinorTickSpacing
public void setMinorTickSpacing(int spacing)
- Sets the distance between minor tick marks along the slider's value scale,
and sends a java.beans.PropertyChangeEvent (with the property name
"minorTickSpacing") to all registered listeners.
getSnapToTicks
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.
setSnapToTicks
public void setSnapToTicks(boolean snap)
- Sets the flag that controls whether the slider thumb will snap to ticks
and sends a java.beans.PropertyChangeEvent (with the property name
'snapToTicks') to all registered listeners. Sliders that snap to ticks
will automatically move the thumb to the nearest tick mark.
getPaintTicks
public boolean getPaintTicks()
- Returns the flag that controls whether or not tick marks are painted along
the slider's value scale.
setPaintTicks
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 a java.beans.PropertyChangeEvent (with
the property name "paintTicks") to all registered listeners. In
addition to setting this property to
true, 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.
getPaintTrack
public boolean getPaintTrack()
- Returns the flag that controls whether or not the track is painted.
setPaintTrack
public void setPaintTrack(boolean paint)
- Sets the flag that controls whether or not the track is painted, and
sends a java.beans.PropertyChangeEvent (for the "paintTrack" property) to all
registered listeners.
getPaintLabels
public boolean getPaintLabels()
- Returns the flag that controls whether or not labels are painted for the
tick marks along the slider.
setPaintLabels
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 a java.beans.PropertyChangeEvent (with
the property name "paintLabels") to all registered listeners.
paramString
protected java.lang.String paramString()
- Returns an implementation-dependent string describing the attributes of
this
JSlider.- Overrides:
paramStringin classJComponent
getAccessibleContext
public javax.accessibility.AccessibleContext getAccessibleContext()
- Returns the object that provides accessibility features for this
JSlidercomponent.- Specified by:
getAccessibleContextin interfacejavax.accessibility.Accessible- Overrides:
getAccessibleContextin classJComponent
|
|||||||||
| Home >> All >> javax >> [ swing overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC