Class JSlider
- All Implemented Interfaces:
-
ImageObserver,MenuContainer,Serializable,Accessible,SwingConstants
@JavaBean(defaultProperty="UI", description="A component that supports selecting a integer value from a range.") public class JSlider extends JComponent implements SwingConstants, Accessible
The slider can show both major tick marks, and minor tick marks between the major ones. The number of values between the tick marks is controlled with setMajorTickSpacing and setMinorTickSpacing. Painting of tick marks is controlled by setPaintTicks.
Sliders can also print text labels at regular intervals (or at arbitrary locations) along the slider track. Painting of labels is controlled by setLabelTable and setPaintLabels.
For further information and examples see How to Use Sliders, a section in The Java Tutorial.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder.
- Since:
- 1.2
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
protected class |
JSlider.AccessibleJSlider |
This class implements accessibility support for the JSlider class. |
Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
protected 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 declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields declared in 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
| Constructor | Description |
|---|---|
JSlider() |
Creates a horizontal slider with the range 0 to 100 and an initial value of 50. |
JSlider |
Creates a slider using the specified orientation with the range 0 to 100 and an initial value of 50. |
JSlider |
Creates a horizontal slider using the specified min and max with an initial value equal to the average of the min plus max. |
JSlider |
Creates a horizontal slider using the specified min, max and value. |
JSlider |
Creates a slider with the specified orientation and the specified minimum, maximum, and initial values. |
JSlider |
Creates a horizontal slider using the specified BoundedRangeModel. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
addChangeListener |
Adds a ChangeListener to the slider. |
protected ChangeListener |
createChangeListener() |
Subclasses that want to handle ChangeEvents from the model differently can override this to return an instance of a custom ChangeListener implementation. |
Hashtable<Integer, |
createStandardLabels |
Creates a Hashtable of numerical text labels, starting at the slider minimum, and using the increment specified. |
Hashtable<Integer, |
createStandardLabels |
Creates a Hashtable of numerical text labels, starting at the starting point specified, and using the increment specified. |
protected void |
fireStateChanged() |
Send a ChangeEvent, whose source is this JSlider, to all ChangeListeners that have registered interest in ChangeEvents. |
AccessibleContext |
getAccessibleContext() |
Gets the AccessibleContext associated with this JSlider. |
ChangeListener[] |
getChangeListeners() |
Returns an array of all the ChangeListeners added to this JSlider with addChangeListener(). |
int |
getExtent() |
Returns the "extent" from the BoundedRangeModel. |
boolean |
getInverted() |
Returns true if the value-range shown for the slider is reversed, |
Dictionary |
getLabelTable() |
Returns the dictionary of what labels to draw at which values. |
int |
getMajorTickSpacing() |
This method returns the major tick spacing. |
int |
getMaximum() |
Returns the maximum value supported by the slider from the BoundedRangeModel. |
int |
getMinimum() |
Returns the minimum value supported by the slider from the BoundedRangeModel. |
int |
getMinorTickSpacing() |
This method returns the minor tick spacing. |
BoundedRangeModel |
getModel() |
Returns the BoundedRangeModel that handles the slider's three fundamental properties: minimum, maximum, value. |
int |
getOrientation() |
Return this slider's vertical or horizontal orientation. |
boolean |
getPaintLabels() |
Tells if labels are to be painted. |
boolean |
getPaintTicks() |
Tells if tick marks are to be painted. |
boolean |
getPaintTrack() |
Tells if the track (area the slider slides in) is to be painted. |
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. |
SliderUI |
getUI() |
Gets the UI object which implements the L&F for this component. |
String |
getUIClassID() |
Returns the name of the L&F class that renders this component. |
int |
getValue() |
Returns the slider's current value from the BoundedRangeModel. |
boolean |
getValueIsAdjusting() |
Returns the valueIsAdjusting property from the model. |
boolean |
imageUpdate |
Repaints the component when the image has changed. |
protected String |
paramString() |
Returns a string representation of this JSlider. |
void |
removeChangeListener |
Removes a ChangeListener from the slider. |
void |
setExtent |
Sets the size of the range "covered" by the knob. |
void |
setFont |
Sets the font for this component. |
void |
setInverted |
Specify true to reverse the value-range shown for the slider and false to put the value range in the normal order. |
void |
setLabelTable |
Used to specify what label will be drawn at any given value. |
void |
setMajorTickSpacing |
This method sets the major tick spacing. |
void |
setMaximum |
Sets the slider's maximum value to maximum. |
void |
setMinimum |
Sets the slider's minimum value to minimum. |
void |
setMinorTickSpacing |
This method sets the minor tick spacing. |
void |
setModel |
Sets the BoundedRangeModel that handles the slider's three fundamental properties: minimum, maximum, value. |
void |
setOrientation |
Set the slider's orientation to either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL. |
void |
setPaintLabels |
Determines whether labels are painted on the slider. |
void |
setPaintTicks |
Determines whether tick marks are painted on the slider. |
void |
setPaintTrack |
Determines whether the track is painted on the slider. |
void |
setSnapToTicks |
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 |
setUI |
Sets the UI object which implements the L&F for this component. |
void |
setValue |
Sets the slider's current value to n. |
void |
setValueIsAdjusting |
Sets the model's valueIsAdjusting property. |
protected void |
updateLabelUIs() |
Updates the UIs for the labels in the label table by calling updateUI on each label. |
void |
updateUI() |
Resets the UI property to a value from the current look and feel. |
Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods declared in class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods declared in class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
Field Details
sliderModel
protected BoundedRangeModel sliderModel
majorTickSpacing
protected int majorTickSpacing
minorTickSpacing
protected int minorTickSpacing
- See Also:
snapToTicks
protected boolean snapToTicks
- See Also:
orientation
protected int orientation
- See Also:
changeListener
protected ChangeListener changeListener
ChangeListener returned from createChangeListener, which by default just forwards events to ChangeListeners (if any) added directly to the slider.changeEvent
protected transient ChangeEvent changeEvent
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:
Constructor Details
JSlider
public JSlider()
JSlider
public JSlider(int orientation)
0 to 100 and an initial value of 50. The orientation can be either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.- Parameters:
-
orientation- the orientation of the slider - Throws:
-
IllegalArgumentException- if orientation is not one ofVERTICAL,HORIZONTAL - See Also:
JSlider
public JSlider(int min, int 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 BoundedRangeModel documentation for details.
- Parameters:
-
min- the minimum value of the slider -
max- the maximum value of the slider - See Also:
JSlider
public JSlider(int min, int max, int 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 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 - See Also:
JSlider
public JSlider(int orientation, int min, int max, int value)
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 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 - Throws:
-
IllegalArgumentException- if orientation is not one ofVERTICAL,HORIZONTAL - See Also:
JSlider
public JSlider(BoundedRangeModel brm)
- Parameters:
-
brm- aBoundedRangeModelfor the slider
Method Details
getUI
public SliderUI getUI()
- Overrides:
-
getUIin classJComponent - Returns:
- the SliderUI object that implements the Slider L&F
setUI
@BeanProperty(hidden=true, visualUpdate=true, description="The UI object that implements the slider\'s LookAndFeel.") public void setUI(SliderUI ui)
- Parameters:
-
ui- the SliderUI L&F object - See Also:
updateUI
public void updateUI()
- Overrides:
-
updateUIin classJComponent - See Also:
getUIClassID
@BeanProperty(bound=false) public String getUIClassID()
- Overrides:
-
getUIClassIDin classJComponent - Returns:
- the string "SliderUI"
- See Also:
createChangeListener
protected ChangeListener createChangeListener()
ChangeEvents from the model differently can override this to return an instance of a custom ChangeListener implementation. The default ChangeListener simply calls the fireStateChanged method to forward ChangeEvents to the ChangeListeners that have been added directly to the slider.- Returns:
- a instance of new
ChangeListener - See Also:
addChangeListener
public void addChangeListener(ChangeListener l)
- Parameters:
-
l- the ChangeListener to add - See Also:
removeChangeListener
public void removeChangeListener(ChangeListener l)
- Parameters:
-
l- the ChangeListener to remove - See Also:
getChangeListeners
@BeanProperty(bound=false) public ChangeListener[] getChangeListeners()
ChangeListeners added to this JSlider with addChangeListener().- Returns:
- all of the
ChangeListeners added or an empty array if no listeners have been added - Since:
- 1.4
fireStateChanged
protected void fireStateChanged()
ChangeEvent, whose source is this JSlider, to all ChangeListeners that have registered interest in ChangeEvents. This method is called each time a ChangeEvent is received from the model. The event instance is created if necessary, and stored in changeEvent.
getModel
public BoundedRangeModel getModel()
BoundedRangeModel that handles the slider's three fundamental properties: minimum, maximum, value.- Returns:
- the data model for this component
- See Also:
setModel
@BeanProperty(description="The sliders BoundedRangeModel.") public void setModel(BoundedRangeModel newModel)
BoundedRangeModel that handles the slider's three fundamental properties: minimum, maximum, value. Attempts to pass a null model to this method result in undefined behavior, and, most likely, exceptions.
- Parameters:
-
newModel- the new,non-nullBoundedRangeModelto use - See Also:
getValue
public int getValue()
BoundedRangeModel.- Returns:
- the current value of the slider
- See Also:
setValue
@BeanProperty(bound=false, preferred=true, description="The sliders current value.") public void setValue(int n)
n. This method forwards the new value to the model. The data model (an instance of BoundedRangeModel) handles any mathematical issues arising from assigning faulty values. See the BoundedRangeModel documentation for details.
If the new value is different from the previous value, all change listeners are notified.
- Parameters:
-
n- the new value - See Also:
getMinimum
public int getMinimum()
BoundedRangeModel.- Returns:
- the value of the model's minimum property
- See Also:
setMinimum
@BeanProperty(preferred=true, description="The sliders minimum value.") public void setMinimum(int minimum)
minimum. This method forwards the new minimum value to the model. The data model (an instance of BoundedRangeModel) handles any mathematical issues arising from assigning faulty values. See the BoundedRangeModel documentation for details.
If the new minimum value is different from the previous minimum value, all change listeners are notified.
- Parameters:
-
minimum- the new minimum - See Also:
getMaximum
public int getMaximum()
BoundedRangeModel.- Returns:
- the value of the model's maximum property
- See Also:
setMaximum
@BeanProperty(preferred=true, description="The sliders maximum value.") public void setMaximum(int maximum)
maximum. This method forwards the new maximum value to the model. The data model (an instance of BoundedRangeModel) handles any mathematical issues arising from assigning faulty values. See the BoundedRangeModel documentation for details.
If the new maximum value is different from the previous maximum value, all change listeners are notified.
- Parameters:
-
maximum- the new maximum - See Also:
getValueIsAdjusting
public boolean getValueIsAdjusting()
valueIsAdjusting property from the model. For details on how this is used, see the setValueIsAdjusting documentation.- Returns:
- the value of the model's
valueIsAdjustingproperty - See Also:
setValueIsAdjusting
@BeanProperty(bound=false, expert=true, description="True if the slider knob is being dragged.") public void setValueIsAdjusting(boolean b)
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.- Parameters:
-
b- the new value for thevalueIsAdjustingproperty - See Also:
getExtent
public int getExtent()
BoundedRangeModel. This represents the range of values "covered" by the knob.- Returns:
- an int representing the extent
- See Also:
setExtent
@BeanProperty(bound=false, expert=true, description="Size of the range covered by the knob.") public void setExtent(int extent)
The data model (an instance of BoundedRangeModel) handles any mathematical issues arising from assigning faulty values. See the 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 - See Also:
getOrientation
public int getOrientation()
- Returns:
-
SwingConstants.VERTICALorSwingConstants.HORIZONTAL - See Also:
setOrientation
@BeanProperty(preferred=true, visualUpdate=true, enumerationValues={"JSlider.VERTICAL","JSlider.HORIZONTAL"}, description="Set the scrollbars orientation to either VERTICAL or HORIZONTAL.") public void setOrientation(int orientation) SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.- Parameters:
-
orientation-HORIZONTALorVERTICAL - Throws:
-
IllegalArgumentException- if orientation is not one ofVERTICAL,HORIZONTAL - See Also:
setFont
public void setFont(Font font)
- Overrides:
-
setFontin classJComponent - Parameters:
-
font- the desiredFontfor this component - Since:
- 1.6
- See Also:
imageUpdate
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
imageUpdate method of an ImageObserver is called when more information about an image which had been previously requested using an asynchronous routine such as the drawImage method of Graphics becomes available. See the definition of imageUpdate for more information on this method and its arguments. The imageUpdate method of Component incrementally draws an image on the component as more of the bits of the image are available.
If the system property awt.image.incrementaldraw is missing or has the value true, the image is incrementally drawn. If the system property has any other value, then the image is not drawn until it has been completely loaded.
Also, if incremental drawing is in effect, the value of the system property awt.image.redrawrate is interpreted as an integer to give the maximum redraw rate, in milliseconds. If the system property is missing or cannot be interpreted as an integer, the redraw rate is once every 100ms.
The interpretation of the x, y, width, and height arguments depends on the value of the infoflags argument.
- Specified by:
-
imageUpdatein interfaceImageObserver - Overrides:
-
imageUpdatein classComponent - Parameters:
-
img- the image being observed -
infoflags- seeimageUpdatefor more information -
x- the x coordinate -
y- the y coordinate -
w- the width -
h- the height - Returns:
-
falseif the infoflags indicate that the image is completely loaded;trueotherwise. - Since:
- 1.7
- See Also:
-
ImageObserverGraphics.drawImage(Image, int, int, Color, java.awt.image.ImageObserver)Graphics.drawImage(Image, int, int, java.awt.image.ImageObserver)Graphics.drawImage(Image, int, int, int, int, Color, java.awt.image.ImageObserver)Graphics.drawImage(Image, int, int, int, int, java.awt.image.ImageObserver)ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
getLabelTable
public Dictionary getLabelTable()
- Returns:
- the
Dictionarycontaining labels and where to draw them
setLabelTable
@BeanProperty(hidden=true, visualUpdate=true, description="Specifies what labels will be drawn for any given value.") public void setLabelTable(Dictionary labels)
{ Integer value, java.swing.JComponent label }. An easy way to generate a standard table of value labels is by using the createStandardLabels method.
Once the labels have been set, this method calls updateLabelUIs(). Note that the labels are only painted if the paintLabels property is true.
- Parameters:
-
labels- newDictionaryof labels, ornullto remove all labels - See Also:
updateLabelUIs
protected void updateLabelUIs()
updateUI on each label. The UIs are updated from the current look and feel. The labels are also set to their preferred size.createStandardLabels
public Hashtable<Integer,JComponent> createStandardLabels(int increment)
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 Hashtable must be passed into setLabelTable, and setPaintLabels must be set to true.
For further details on the makeup of the returned Hashtable, see the setLabelTable documentation.
- Parameters:
-
increment- distance between labels in the generated hashtable - Returns:
- a new
Hashtableof labels - Throws:
-
IllegalArgumentException- ifincrementis less than or equal to zero - See Also:
createStandardLabels
public Hashtable<Integer,JComponent> createStandardLabels(int increment, int start)
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 Hashtable must be passed into setLabelTable, and setPaintLabels must be set to true.
For further details on the makeup of the returned Hashtable, see the setLabelTable documentation.
- Parameters:
-
increment- distance between labels in the generated hashtable -
start- value at which the labels will begin - Returns:
- a new
Hashtableof labels - Throws:
-
IllegalArgumentException- ifstartis out of range, or ifincrementis less than or equal to zero - See Also:
getInverted
public boolean getInverted()
- Returns:
- true if the slider values are reversed from their normal order
- See Also:
setInverted
@BeanProperty(visualUpdate=true, description="If true reverses the slider values from their normal order") public void setInverted(boolean b)
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 false.
- Parameters:
-
b- true to reverse the slider values from their normal order
getMajorTickSpacing
public int getMajorTickSpacing()
- Returns:
- the number of values between major ticks
- See Also:
setMajorTickSpacing
@BeanProperty(visualUpdate=true, description="Sets the number of values between major tick marks.") public void setMajorTickSpacing(int n)
In order for major ticks to be painted, setPaintTicks must be set to 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 > 0, and getPaintLabels returns true, a standard label table will be generated (by calling 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 setLabelTable.
- Parameters:
-
n- new value for themajorTickSpacingproperty - See Also:
getMinorTickSpacing
public int getMinorTickSpacing()
- Returns:
- the number of values between minor ticks
- See Also:
setMinorTickSpacing
@BeanProperty(visualUpdate=true, description="Sets the number of values between minor tick marks.") public void setMinorTickSpacing(int n)
In order for minor ticks to be painted, setPaintTicks must be set to true.
- Parameters:
-
n- new value for theminorTickSpacingproperty - See Also:
getSnapToTicks
public boolean getSnapToTicks()
- Returns:
- true if the value snaps to the nearest tick mark, else false
- See Also:
setSnapToTicks
@BeanProperty(description="If true snap the knob to the nearest tick mark.") public void setSnapToTicks(boolean b)
false.- Parameters:
-
b- true to snap the knob to the nearest tick mark - See Also:
getPaintTicks
public boolean getPaintTicks()
- Returns:
- true if tick marks are painted, else false
- See Also:
setPaintTicks
@BeanProperty(visualUpdate=true, description="If true tick marks are painted on the slider.") public void setPaintTicks(boolean b)
false.- Parameters:
-
b- whether or not tick marks should be painted - See Also:
getPaintTrack
public boolean getPaintTrack()
- Returns:
- true if track is painted, else false
- See Also:
setPaintTrack
@BeanProperty(visualUpdate=true, description="If true, the track is painted on the slider.") public void setPaintTrack(boolean b)
true. It is up to the look and feel to honor this property, some may choose to ignore it.- Parameters:
-
b- whether or not to paint the slider track - See Also:
getPaintLabels
public boolean getPaintLabels()
- Returns:
- true if labels are painted, else false
- See Also:
setPaintLabels
@BeanProperty(visualUpdate=true, description="If true labels are painted on the slider.") public void setPaintLabels(boolean b)
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 > 0, a standard label table will be generated (by calling createStandardLabels) with labels at the major tick marks. The label table is then set on the slider by calling setLabelTable.
By default, this property is false.
- Parameters:
-
b- whether or not to paint labels - See Also:
paramString
protected String paramString()
null.- Overrides:
-
paramStringin classJComponent - Returns:
- a string representation of this JSlider.
getAccessibleContext
@BeanProperty(bound=false) public AccessibleContext getAccessibleContext()
- Specified by:
-
getAccessibleContextin interfaceAccessible - Overrides:
-
getAccessibleContextin classComponent - Returns:
- an AccessibleJSlider that serves as the AccessibleContext of this JSlider
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/JSlider.html