All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JSlider

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.swing.JSlider

public class JSlider
extends JComponent
implements SwingConstants, Accessible
A component that lets the user graphically select a value by slding a knob within a bounded interval. The slider can show both major tick marks and minor tick marks between them. The number of pixels between the tick marks is controlled with setMajorTickSpacing and setMinorTickSpacing.

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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.


Variable Index

 o changeEvent
Only one ChangeEvent is needed per slider instance since the event's only (read-only) state is the source property.
 o changeListener
The changeListener (no suffix) is the listener we add to the Sliders model.
 o majorTickSpacing
The number of pixels between the major tick marks -- the larger marks that break up the minor tick marks.
 o minorTickSpacing
The number of pixels between the minor tick marks -- the smaller marks that occur between the major tick marks.
 o orientation
 o sliderModel
The data model that handles the numeric maximum value, minimum value, and current-position value for the slider.
 o 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.

Constructor Index

 o JSlider()
Creates a horizontal slider with the range 0 to 100 and an intitial value of 50.
 o JSlider(int, int, int, int)
Creates a slider with the specified orientation and the specified mimimum, maximum, and initial values.

Method Index

 o addChangeListener(ChangeListener)
Adds a ChangeListener to the slider.
 o createChangeListener()
Subclasses that want to handle model ChangeEvents differently can override this method to return their own ChangeListener implementation.
 o createStandardLabels(int)
Creates a hashtable that will draw text labels starting at the slider minimum using the increment specified.
 o createStandardLabels(int, int)
Creates a hashtable that will draw text labels starting at the start point specified using the increment specified.
 o fireStateChanged()
Send a ChangeEvent, whose source is this Slider, to each listener.
 o getAccessibleContext()
Get the AccessibleContext associated with this JComponent
 o getExtent()
 o getInverted()
Returns true if the value-range shown for the slider is reversed, with the maximum value at the left end of a horizontal slider or at the bottom of a vertical one.
 o getLabelTable()
Returns the dictionary of what labels to draw at which values.
 o getMajorTickSpacing()
 o getMaximum()
Returns the maximum value supported by the slider.
 o getMinimum()
Returns the minimum value supported by the slider.
 o getMinorTickSpacing()
 o getModel()
Returns data model that handles the sliders three fundamental properties: minimum, maximum, value.
 o getOrientation()
 o getPaintLabels()
 o getPaintTicks()
 o getSnapToTicks()
Returns true if the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob.
 o getUI()
Gets the UI object which implements the L&F for this component.
 o getUIClassID()
Returns the name of the L&F class that renders this component.
 o getValue()
Returns the sliders value.
 o getValueIsAdjusting()
True if the slider knob is being dragged.
 o removeChangeListener(ChangeListener)
Removes a ChangeListener from the slider.
 o setExtent(int)
Sets the size of the range "covered" by the knob.
 o setInverted(boolean)
Specify true to reverse the value-range shown for the slider so that the maximum value is at the left end of a horizontal slider or at the bottom of a vertical one.
 o setLabelTable(Dictionary)
Used to specify what label will be drawn at any given value.
 o setMajorTickSpacing(int)
Sets the number of pixels between major tick marks.
 o setMaximum(int)
Sets the models maximum property.
 o setMinimum(int)
Sets the models minimum property.
 o setMinorTickSpacing(int)
Sets the number of pixels between minor tick marks.
 o setModel(BoundedRangeModel)
Sets the model that handles the sliders three fundamental properties: minimum, maximum, value.
 o setOrientation(int)
Set the scrollbars orientation to either VERTICAL or HORIZONTAL.
 o setPaintLabels(boolean)
Determines whether labels are painted on the slider.
 o setPaintTicks(boolean)
Determines whether tick marks are painted on the slider.
 o setSnapToTicks(boolean)
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.
 o setUI(SliderUI)
Sets the UI object which implements the L&F for this component.
 o setValue(int)
Sets the sliders current value.
 o setValueIsAdjusting(boolean)
Sets the models valueIsAdjusting property.
 o toString()
Returns a string containing that displays and identifies this object's propeties.
 o updateLabelUIs()
Called internally to replace the label UIs with the latest versions from the UIFactory when the UIFactory notifies us via updateUI that the L&F has changed.
 o updateUI()
Notification from the UIFactory that the L&F has changed.

Variables

 o sliderModel
 protected BoundedRangeModel sliderModel
The data model that handles the numeric maximum value, minimum value, and current-position value for the slider.

 o majorTickSpacing
 protected int majorTickSpacing
The number of pixels between the major tick marks -- the larger marks that break up the minor tick marks.

 o minorTickSpacing
 protected int minorTickSpacing
The number of pixels between the minor tick marks -- the smaller marks that occur between the major tick marks.

See Also:
setMinorTickSpacing
 o snapToTicks
 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.

See Also:
setSnapToTicks
 o orientation
 protected int orientation
See Also:
setOrientation
 o changeListener
 protected ChangeListener changeListener
The changeListener (no suffix) is the listener we add to the Sliders model. By default this listener just forwards events to ChangeListeners (if any) added directly to the slider.

See Also:
addChangeListener, createChangeListener
 o changeEvent
 protected transient ChangeEvent 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.

See Also:
fireStateChanged

Constructors

 o JSlider
 public JSlider(int orientation,
                int min,
                int max,
                int value)
Creates a slider with the specified orientation and the specified mimimum, maximum, and initial values.

Throws: IllegalArgumentException
if orientation is not one of VERTICAL, HORIZONTAL
See Also:
setOrientation, setMinimum, setMaximum, setValue
 o JSlider
 public JSlider()
Creates a horizontal slider with the range 0 to 100 and an intitial value of 50.

Methods

 o getUI
 public SliderUI getUI()
Gets the UI object which implements the L&F for this component.

Returns:
the SliderUI object that implements the Slider L&F
 o setUI
 public void setUI(SliderUI ui)
Sets the UI object which implements the L&F for this component.

Parameters:
ui - the SliderUI L&F object
See Also:
getUI
 o updateUI
 public void updateUI()
Notification from the UIFactory that the L&F has changed. Called to replace the UI with the latest version from the default UIFactory.

Overrides:
updateUI in class JComponent
See Also:
updateUI
 o getUIClassID
 public String getUIClassID()
Returns the name of the L&F class that renders this component.

Returns:
"SliderUI"
Overrides:
getUIClassID in class JComponent
See Also:
getUIClassID, getUI
 o createChangeListener
 protected ChangeListener createChangeListener()
Subclasses that want to handle model ChangeEvents differently can override this method to return their own ChangeListener implementation. The default ChangeListener just forwards ChangeEvents to the ChangeListeners added directly to the slider.

See Also:
fireStateChanged
 o addChangeListener
 public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the slider.

Parameters:
l - the ChangeListener to add
See Also:
fireStateChanged, removeChangeListener
 o removeChangeListener
 public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the slider.

Parameters:
l - the ChangeListener to remove
See Also:
fireStateChanged, addChangeListener
 o fireStateChanged
 protected void fireStateChanged()
Send a ChangeEvent, whose source is this Slider, to each listener. This method method is called each time a ChangeEvent is received from the model.

See Also:
addChangeListener, EventListenerList
 o getModel
 public BoundedRangeModel getModel()
Returns data model that handles the sliders three fundamental properties: minimum, maximum, value.

See Also:
setModel
 o setModel
 public void setModel(BoundedRangeModel newModel)
Sets the model that handles the sliders three fundamental properties: minimum, maximum, value.

See Also:
getModel
 o getValue
 public int getValue()
Returns the sliders value.

Returns:
the models value property
See Also:
setValue
 o setValue
 public void setValue(int n)
Sets the sliders current value. This method just forwards the value to the model.

See Also:
getValue
 o getMinimum
 public int getMinimum()
Returns the minimum value supported by the slider.

Returns:
the value of the models minimum property
See Also:
setMinimum
 o setMinimum
 public void setMinimum(int minimum)
Sets the models minimum property.

See Also:
getMinimum, setMinimum
 o getMaximum
 public int getMaximum()
Returns the maximum value supported by the slider.

Returns:
the value of the models maximum property
See Also:
setMaximum
 o setMaximum
 public void setMaximum(int maximum)
Sets the models maximum property.

See Also:
getMaximum, setMaximum
 o getValueIsAdjusting
 public boolean getValueIsAdjusting()
True if the slider knob is being dragged.

Returns:
the value of the models valueIsAdjusting property
See Also:
setValueIsAdjusting
 o setValueIsAdjusting
 public void setValueIsAdjusting(boolean b)
Sets the models valueIsAdjusting property. Slider look and feel implementations should set this property to true when a knob drag begins, and to false when the drag ends. The slider model will not generate ChangeEvents while valueIsAdjusting is true.

See Also:
getValueIsAdjusting, setValueIsAdjusting
 o getExtent
 public int getExtent()
Returns:
the range of values "covered" by the knob.
See Also:
setExtent, getExtent
 o 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.

See Also:
getExtent, setExtent
 o getOrientation
 public int getOrientation()
Returns:
VERTICAL or HORIZONTAL
See Also:
setOrientation
 o setOrientation
 public void setOrientation(int orientation)
Set the scrollbars orientation to either VERTICAL or HORIZONTAL.

Throws: IllegalArgumentException
if orientation is not one of VERTICAL, HORIZONTAL
See Also:
getOrientation
 o getLabelTable
 public Dictionary getLabelTable()
Returns the dictionary of what labels to draw at which values.

Returns:
the Dictionary containing labels and where to draw them
 o setLabelTable
 public void setLabelTable(Dictionary labels)
Used to specify what label will be drawn at any given value. The key-value pairs are of this format: { Integer value, java.awt.Component label }

See Also:
createStandardLabels, getLabelTable
 o updateLabelUIs
 protected void updateLabelUIs()
Called internally to replace the label UIs with the latest versions from the UIFactory when the UIFactory notifies us via updateUI that the L&F has changed.

See Also:
updateUI
 o createStandardLabels
 public Hashtable createStandardLabels(int increment)
Creates a hashtable that will draw text labels starting at the slider minimum using the increment specified. If you call createStandardLabels( 10 ) and the slider minimum is zero, then it will make labels for the values 0, 10, 20, 30, and so on.

See Also:
setLabelTable
 o createStandardLabels
 public Hashtable createStandardLabels(int increment,
                                       int start)
Creates a hashtable that will draw text labels starting at the start point specified using the increment specified. If you call createStandardLabels( 10, 2 ), then it will make labels for the values 2, 12, 22, 32, and so on.

See Also:
setLabelTable
 o getInverted
 public boolean getInverted()
Returns true if the value-range shown for the slider is reversed, with the maximum value at the left end of a horizontal slider or at the bottom of a vertical one.

Returns:
true if the slider values are reversed from their normal order
 o setInverted
 public void setInverted(boolean b)
Specify true to reverse the value-range shown for the slider so that the maximum value is at the left end of a horizontal slider or at the bottom of a vertical one. Specify false to put the value range in the normal order.

Parameters:
b - true to reverse the slider values from their normal order
 o getMajorTickSpacing
 public int getMajorTickSpacing()
Returns:
the number of pixels between major ticks
See Also:
setMajorTickSpacing
 o setMajorTickSpacing
 public void setMajorTickSpacing(int n)
Sets the number of pixels between major tick marks.

See Also:
getMajorTickSpacing
 o getMinorTickSpacing
 public int getMinorTickSpacing()
Returns:
the number of pixels between minor ticks
See Also:
getMinorTickSpacing
 o setMinorTickSpacing
 public void setMinorTickSpacing(int n)
Sets the number of pixels between minor tick marks.

See Also:
getMinorTickSpacing
 o getSnapToTicks
 public boolean getSnapToTicks()
Returns true if the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob.

Returns:
true if the value snaps to the nearest tick mark, else false
See Also:
setSnapToTicks
 o setSnapToTicks
 public void setSnapToTicks(boolean 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.

Parameters:
b - true to snap the knob to the nearest tick mark
See Also:
getSnapToTicks
 o getPaintTicks
 public boolean getPaintTicks()
Returns:
true if tick marks are painted, else false
See Also:
setPaintTicks
 o setPaintTicks
 public void setPaintTicks(boolean b)
Determines whether tick marks are painted on the slider.

See Also:
getPaintTicks
 o getPaintLabels
 public boolean getPaintLabels()
Returns:
true if labels are painted, else false
See Also:
setPaintLabels
 o setPaintLabels
 public void setPaintLabels(boolean b)
Determines whether labels are painted on the slider.

See Also:
getPaintLabels
 o toString
 public String toString()
Returns a string containing that displays and identifies this object's propeties.

Overrides:
toString in class Component
 o getAccessibleContext
 public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JComponent

Returns:
the AccessibleContext of this JComponent
Overrides:
getAccessibleContext in class JComponent

All Packages  Class Hierarchy  This Package  Previous  Next  Index