This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.swing
class JSlider

java.lang.Object extended by java.awt.Component extended by java.awt.Container extended by javax.swing.JComponent extended by javax.swing.JSlider
All Implemented Interfaces:
MenuContainer, ImageObserver, Serializable, Accessible, SwingConstants, TransferHandler.HasGetTransferHandler

Most common way to construct:

JSlider slider = new JSlider();

Based on 100 examples


public class JSlider
extends JComponent
implements SwingConstants, Accessible

A component that lets the user graphically select a value by sliding a knob within a bounded 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 {@code setPaintTicks}.

Sliders can also print text labels at regular intervals (or at arbitrary locations) along the slider track. Painting of labels is controlled by {@code setLabelTable} and {@code 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 JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.


Nested Class Summary
protected class

           This class implements accessibility support for the JSlider 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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
   
Field Summary
protected transient ChangeEvent changeEvent
          Only one ChangeEvent is needed per slider instance since the event's only (read-only) state is the source property.
protected ChangeListener changeListener
          The changeListener (no suffix) is the listener we add to the slider's model.
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.
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.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary

          Creates a horizontal slider with the range 0 to 100 and an initial value of 50.

          Creates a horizontal slider using the specified BoundedRangeModel.
JSlider(int orientation)

          Creates a slider using the specified orientation with the range to and an initial value of .
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.
JSlider(int min, int max, int value)

          Creates a horizontal slider using the specified min, max and value.
JSlider(int orientation, int min, int max, int value)

          Creates a slider with the specified orientation and the specified minimum, maximum, and initial values.
 
Method Summary
 void

          Adds a ChangeListener to the slider.
protected ChangeListener

          Subclasses that want to handle s from the model differently can override this to return an instance of a custom ChangeListener implementation.
 Hashtable
createStandardLabels(int increment)

          Creates a of numerical text labels, starting at the slider minimum, and using the increment specified.
 Hashtable
createStandardLabels(int increment, int start)

          Creates a of numerical text labels, starting at the starting point specified, and using the increment specified.
protected void

          Send a , whose source is this , to all s that have registered interest in s.
 AccessibleContext

          Gets the AccessibleContext associated with this JSlider.
 ChangeListener[]

          Returns an array of all the ChangeListeners added to this JSlider with addChangeListener().
 int

          Returns the "extent" from the BoundedRangeModel.
 boolean

          Returns true if the value-range shown for the slider is reversed,
 Dictionary

          Returns the dictionary of what labels to draw at which values.
 int

          This method returns the major tick spacing.
 int

          Returns the maximum value supported by the slider from the BoundedRangeModel.
 int

          Returns the minimum value supported by the slider from the BoundedRangeModel.
 int

          This method returns the minor tick spacing.
 BoundedRangeModel

          Returns the that handles the slider's three fundamental properties: minimum, maximum, value.
 int

          Return this slider's vertical or horizontal orientation.
 boolean

          Tells if labels are to be painted.
 boolean

          Tells if tick marks are to be painted.
 boolean

          Tells if the track (area the slider slides in) is to be painted.
 boolean

          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.
 SliderUI

          Gets the UI object which implements the L&F for this component.
 String

          Returns the name of the L&F class that renders this component.
 int

          Returns the slider's current value from the .
 boolean

          Returns the property from the model.
protected String

          Returns a string representation of this JSlider.
 void

          Removes a ChangeListener from the slider.
 void
setExtent(int extent)

          Sets the size of the range "covered" by the knob.
 void
setFont(Font font)

          Sets the font for this component.
 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.
 void

          Used to specify what label will be drawn at any given value.
 void

          This method sets the major tick spacing.
 void
setMaximum(int maximum)

          Sets the slider's maximum value to .
 void
setMinimum(int minimum)

          Sets the slider's minimum value to .
 void

          This method sets the minor tick spacing.
 void

          Sets the that handles the slider's three fundamental properties: minimum, maximum, value.
 void
setOrientation(int orientation)

          Set the slider's orientation to either or .
 void
setPaintLabels(boolean b)

          Determines whether labels are painted on the slider.
 void
setPaintTicks(boolean b)

          Determines whether tick marks are painted on the slider.
 void
setPaintTrack(boolean b)

          Determines whether the track is painted on the slider.
 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.
 void

          Sets the UI object which implements the L&F for this component.
 void
setValue(int n)

          Sets the slider's current value to .
 void

          Sets the model's property.
protected void

          Updates the UIs for the labels in the label table by calling on each label.
 void

          Resets the UI property to a value from the current look and feel.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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.

changeListener

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

majorTickSpacing

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

minorTickSpacing

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

orientation

protected int orientation
Whether the slider is horizontal or vertical The default is horizontal.

sliderModel

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

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. The default is false.
Constructor Detail

JSlider

public JSlider()
Creates a horizontal slider with the range 0 to 100 and an initial value of 50.


JSlider

public JSlider(BoundedRangeModel brm)
Creates a horizontal slider using the specified BoundedRangeModel.

Parameters:
brm

JSlider

public JSlider(int orientation)
Creates a slider using the specified orientation with the range {@code 0} to {@code 100} and an initial value of {@code 50}. The orientation can be either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.

Parameters:
orientation - the orientation of the slider

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 {@code BoundedRangeModel} documentation for details.

Parameters:
min - the minimum value of the slider
max - the maximum value of the slider

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 {@code BoundedRangeModel} documentation for details.

Parameters:
min - the minimum value of the slider
max - the maximum value of the slider
value - the initial value of the slider

JSlider

public JSlider(int orientation,
               int min,
               int max,
               int value)
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 {@code BoundedRangeModel} documentation for details.

Parameters:
orientation - the orientation of the slider
min - the minimum value of the slider
max - the maximum value of the slider
value - the initial value of the slider
Method Detail

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the slider.

Parameters:
l - the ChangeListener to add

createChangeListener

protected ChangeListener createChangeListener()
Subclasses that want to handle {@code ChangeEvent}s from the model differently can override this to return an instance of a custom ChangeListener implementation. The default {@code ChangeListener} simply calls the {@code fireStateChanged} method to forward {@code ChangeEvent}s to the {@code ChangeListener}s that have been added directly to the slider.


createStandardLabels

public Hashtable createStandardLabels(int increment)
Creates a {@code 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 {@code Hashtable} must be passed into {@code setLabelTable}, and {@code setPaintLabels} must be set to {@code true}.

For further details on the makeup of the returned {@code Hashtable}, see the {@code setLabelTable} documentation.

Parameters:
increment - distance between labels in the generated hashtable
Returns:
a new {@code Hashtable} of labels

createStandardLabels

public Hashtable createStandardLabels(int increment,
                                      int start)
Creates a {@code 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 {@code Hashtable} must be passed into {@code setLabelTable}, and {@code setPaintLabels} must be set to {@code true}.

For further details on the makeup of the returned {@code Hashtable}, see the {@code setLabelTable} documentation.

Parameters:
increment - distance between labels in the generated hashtable
start - value at which the labels will begin
Returns:
a new {@code Hashtable} of labels

fireStateChanged

protected void fireStateChanged()
Send a {@code ChangeEvent}, whose source is this {@code JSlider}, to all {@code ChangeListener}s that have registered interest in {@code ChangeEvent}s. This method is called each time a {@code ChangeEvent} is received from the model.

The event instance is created if necessary, and stored in {@code changeEvent}.


getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JSlider. For sliders, the AccessibleContext takes the form of an AccessibleJSlider. A new AccessibleJSlider instance is created if necessary.

Overrides:
getAccessibleContext in class JComponent
Returns:
an AccessibleJSlider that serves as the AccessibleContext of this JSlider

getChangeListeners

public ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners added to this JSlider with addChangeListener().

Returns:
all of the ChangeListeners added or an empty array if no listeners have been added

getExtent

public int getExtent()
Returns the "extent" from the BoundedRangeModel. This respresents the range of values "covered" by the knob.

Returns:
an int representing the extent

getInverted

public boolean getInverted()
Returns true if the value-range shown for the slider is reversed,

Returns:
true if the slider values are reversed from their normal order

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

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.

Returns:
the number of values between major ticks

getMaximum

public int getMaximum()
Returns the maximum value supported by the slider from the BoundedRangeModel.

Returns:
the value of the model's maximum property

getMinimum

public int getMinimum()
Returns the minimum value supported by the slider from the BoundedRangeModel.

Returns:
the value of the model's minimum property

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.

Returns:
the number of values between minor ticks

getModel

public BoundedRangeModel getModel()
Returns the {@code BoundedRangeModel} that handles the slider's three fundamental properties: minimum, maximum, value.

Returns:
the data model for this component

getOrientation

public int getOrientation()
Return this slider's vertical or horizontal orientation.

Returns:
{@code SwingConstants.VERTICAL} or {@code SwingConstants.HORIZONTAL}

getPaintLabels

public boolean getPaintLabels()
Tells if labels are to be painted.

Returns:
true if labels are painted, else false

getPaintTicks

public boolean getPaintTicks()
Tells if tick marks are to be painted.

Returns:
true if tick marks are painted, else false

getPaintTrack

public boolean getPaintTrack()
Tells if the track (area the slider slides in) is to be painted.

Returns:
true if track is painted, else false

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

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

getUIClassID

public String getUIClassID()
Returns the name of the L&F class that renders this component.

Overrides:
getUIClassID in class JComponent
Returns:
"SliderUI"

getValue

public int getValue()
Returns the slider's current value from the {@code BoundedRangeModel}.

Returns:
the current value of the slider

getValueIsAdjusting

public boolean getValueIsAdjusting()
Returns the {@code valueIsAdjusting} property from the model. For details on how this is used, see the {@code setValueIsAdjusting} documentation.

Returns:
the value of the model's {@code valueIsAdjusting} property

paramString

protected String 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.

Overrides:
paramString in class JComponent
Returns:
a string representation of this JSlider.

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the slider.

Parameters:
l - the ChangeListener to remove

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 {@code BoundedRangeModel}) handles any mathematical issues arising from assigning faulty values. See the {@code BoundedRangeModel} documentation for details.

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

Parameters:
extent - the new extent

setFont

public void setFont(Font font)
{@inheritDoc}

Overrides:
setFont in class JComponent
Parameters:
font

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 {@code false}.

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

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.swing.JComponent label }.

An easy way to generate a standard table of value labels is by using the {@code createStandardLabels} method.

Once the labels have been set, this method calls {@link #updateLabelUIs}. Note that the labels are only painted if the {@code paintLabels} property is {@code true}.

Parameters:
labels - new {@code Dictionary} of labels, or {@code null} to remove all labels

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, {@code setPaintTicks} must be set to {@code 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 {@code > 0}, and {@code getPaintLabels} returns {@code true}, a standard label table will be generated (by calling {@code 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 {@code setLabelTable}.

Parameters:
n - new value for the {@code majorTickSpacing} property

setMaximum

public void setMaximum(int maximum)
Sets the slider's maximum value to {@code maximum}. This method forwards the new maximum value to the model.

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

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

Parameters:
maximum

setMinimum

public void setMinimum(int minimum)
Sets the slider's minimum value to {@code minimum}. This method forwards the new minimum value to the model.

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

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

Parameters:
minimum

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, {@code setPaintTicks} must be set to {@code true}.

Parameters:
n - new value for the {@code minorTickSpacing} property

setModel

public void setModel(BoundedRangeModel newModel)
Sets the {@code BoundedRangeModel} that handles the slider's three fundamental properties: minimum, maximum, value.

Attempts to pass a {@code null} model to this method result in undefined behavior, and, most likely, exceptions.

Parameters:
newModel - the new, {@code non-null} BoundedRangeModel to use

setOrientation

public void setOrientation(int orientation)
Set the slider's orientation to either {@code SwingConstants.VERTICAL} or {@code SwingConstants.HORIZONTAL}.

Parameters:
orientation - {@code HORIZONTAL} or {@code VERTICAL}

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 {@code > 0}, a standard label table will be generated (by calling {@code createStandardLabels}) with labels at the major tick marks. The label table is then set on the slider by calling {@code setLabelTable}.

By default, this property is {@code false}.

Parameters:
b - whether or not to paint labels

setPaintTicks

public void setPaintTicks(boolean b)
Determines whether tick marks are painted on the slider. By default, this property is {@code false}.

Parameters:
b - whether or not tick marks should be painted

setPaintTrack

public void setPaintTrack(boolean b)
Determines whether the track is painted on the slider. By default, this property is {@code true}.

Parameters:
b - whether or not to paint the slider track

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. By default, this property is {@code false}.

Parameters:
b - true to snap the knob to the nearest tick mark

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

setValue

public void setValue(int n)
Sets the slider's current value to {@code n}. This method forwards the new value to the model.

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

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

Parameters:
n - the new value

setValueIsAdjusting

public void setValueIsAdjusting(boolean b)
Sets the model's {@code valueIsAdjusting} property. Slider look and feel implementations should set this property to {@code true} when a knob drag begins, and to {@code false} when the drag ends. The slider model will not generate {@code ChangeEvent}s while {@code valueIsAdjusting} is {@code true}.

Parameters:
b - the new value for the {@code valueIsAdjusting} property

updateLabelUIs

protected void updateLabelUIs()
Updates the UIs for the labels in the label table by calling {@code updateUI} on each label. The UIs are updated from the current look and feel. The labels are also set to their preferred size.


updateUI

public void updateUI()
Resets the UI property to a value from the current look and feel.

Overrides:
updateUI in class JComponent


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.