- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JSlider
-
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants
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 knob is always positioned at the points that match integer values within the specified 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
andsetMinorTickSpacing
. Painting of tick marks is controlled bysetPaintTicks
.Sliders can also print text labels at regular intervals (or at arbitrary locations) along the slider track. Painting of labels is controlled by
setLabelTable
andsetPaintLabels
.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 seeXMLEncoder
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description protected class
JSlider.AccessibleJSlider
This class implements accessibility support for theJSlider
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
Fields Modifier and Type Field and Description protected ChangeEvent
changeEvent
Only oneChangeEvent
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
-
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
-
-
Constructor Summary
Constructors Constructor and Description JSlider()
Creates a horizontal slider with the range 0 to 100 and an initial value of 50.JSlider(BoundedRangeModel brm)
Creates a horizontal slider using the specified BoundedRangeModel.JSlider(int orientation)
Creates a slider using the specified orientation with the range0
to100
and an initial value of50
.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
Methods Modifier and Type Method and Description void
addChangeListener(ChangeListener l)
Adds a ChangeListener to the slider.protected ChangeListener
createChangeListener()
Subclasses that want to handleChangeEvent
s from the model differently can override this to return an instance of a customChangeListener
implementation.Hashtable
createStandardLabels(int increment)
Creates aHashtable
of numerical text labels, starting at the slider minimum, and using the increment specified.Hashtable
createStandardLabels(int increment, int start)
Creates aHashtable
of numerical text labels, starting at the starting point specified, and using the increment specified.protected void
fireStateChanged()
Send aChangeEvent
, whose source is thisJSlider
, to allChangeListener
s that have registered interest inChangeEvent
s.AccessibleContext
getAccessibleContext()
Gets the AccessibleContext associated with this JSlider.ChangeListener[]
getChangeListeners()
Returns an array of all theChangeListener
s added to this JSlider with addChangeListener().int
getExtent()
Returns the "extent" from theBoundedRangeModel
.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 theBoundedRangeModel
.int
getMinimum()
Returns the minimum value supported by the slider from theBoundedRangeModel
.int
getMinorTickSpacing()
This method returns the minor tick spacing.BoundedRangeModel
getModel()
Returns theBoundedRangeModel
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 theBoundedRangeModel
.boolean
getValueIsAdjusting()
Returns thevalueIsAdjusting
property from the model.boolean
imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
Repaints the component when the image has changed.protected String
paramString()
Returns a string representation of this JSlider.void
removeChangeListener(ChangeListener l)
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
setLabelTable(Dictionary labels)
Used to specify what label will be drawn at any given value.void
setMajorTickSpacing(int n)
This method sets the major tick spacing.void
setMaximum(int maximum)
Sets the slider's maximum value tomaximum
.void
setMinimum(int minimum)
Sets the slider's minimum value tominimum
.void
setMinorTickSpacing(int n)
This method sets the minor tick spacing.void
setModel(BoundedRangeModel newModel)
Sets theBoundedRangeModel
that handles the slider's three fundamental properties: minimum, maximum, value.void
setOrientation(int orientation)
Set the slider's orientation to eitherSwingConstants.VERTICAL
orSwingConstants.HORIZONTAL
.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
setUI(SliderUI ui)
Sets the UI object which implements the L&F for this component.void
setValue(int n)
Sets the slider's current value ton
.void
setValueIsAdjusting(boolean b)
Sets the model'svalueIsAdjusting
property.protected void
updateLabelUIs()
Updates the UIs for the labels in the label table by callingupdateUI
on each label.void
updateUI()
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, 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 inherited from 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 inherited from 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, 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, getPeer, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
sliderModel
protected BoundedRangeModel sliderModel
The data model that handles the numeric maximum value, minimum value, and current-position value for 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.- See Also:
setMinorTickSpacing(int)
-
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.- See Also:
setSnapToTicks(boolean)
-
orientation
protected int orientation
Whether the slider is horizontal or vertical The default is horizontal.- See Also:
setOrientation(int)
-
changeListener
protected ChangeListener changeListener
The changeListener (no suffix) is the listener we add to the slider's model. This listener is initialized to theChangeListener
returned fromcreateChangeListener
, which by default just forwards events toChangeListener
s (if any) added directly to the slider.
-
changeEvent
protected transient ChangeEvent changeEvent
Only oneChangeEvent
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()
-
-
Constructor Detail
-
JSlider
public JSlider()
Creates a horizontal slider with the range 0 to 100 and an initial value of 50.
-
JSlider
public JSlider(int orientation)
Creates a slider using the specified orientation with the range0
to100
and an initial value of50
. The orientation can be eitherSwingConstants.VERTICAL
orSwingConstants.HORIZONTAL
.- Parameters:
orientation
- the orientation of the slider- Throws:
IllegalArgumentException
- if orientation is not one ofVERTICAL
,HORIZONTAL
- See Also:
setOrientation(int)
-
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 theBoundedRangeModel
documentation for details.- Parameters:
min
- the minimum value of the slidermax
- the maximum value of the slider- See Also:
BoundedRangeModel
,setMinimum(int)
,setMaximum(int)
-
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 theBoundedRangeModel
documentation for details.- Parameters:
min
- the minimum value of the slidermax
- the maximum value of the slidervalue
- the initial value of the slider- See Also:
BoundedRangeModel
,setMinimum(int)
,setMaximum(int)
,setValue(int)
-
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 eitherSwingConstants.VERTICAL
orSwingConstants.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 theBoundedRangeModel
documentation for details.- Parameters:
orientation
- the orientation of the slidermin
- the minimum value of the slidermax
- the maximum value of the slidervalue
- the initial value of the slider- Throws:
IllegalArgumentException
- if orientation is not one ofVERTICAL
,HORIZONTAL
- See Also:
BoundedRangeModel
,setOrientation(int)
,setMinimum(int)
,setMaximum(int)
,setValue(int)
-
JSlider
public JSlider(BoundedRangeModel brm)
Creates a horizontal slider using the specified BoundedRangeModel.
-
-
Method Detail
-
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
-
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:
UIDefaults.getUI(javax.swing.JComponent)
-
updateUI
public void updateUI()
Resets the UI property to a value from the current look and feel.- Overrides:
updateUI
in classJComponent
- See Also:
JComponent.updateUI()
-
getUIClassID
public String getUIClassID()
Returns the name of the L&F class that renders this component.- Overrides:
getUIClassID
in classJComponent
- Returns:
- "SliderUI"
- See Also:
JComponent.getUIClassID()
,UIDefaults.getUI(javax.swing.JComponent)
-
createChangeListener
protected ChangeListener createChangeListener()
Subclasses that want to handleChangeEvent
s from the model differently can override this to return an instance of a customChangeListener
implementation. The defaultChangeListener
simply calls thefireStateChanged
method to forwardChangeEvent
s to theChangeListener
s that have been added directly to the slider.
-
addChangeListener
public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the slider.- Parameters:
l
- the ChangeListener to add- See Also:
fireStateChanged()
,removeChangeListener(javax.swing.event.ChangeListener)
-
removeChangeListener
public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the slider.- Parameters:
l
- the ChangeListener to remove- See Also:
fireStateChanged()
,addChangeListener(javax.swing.event.ChangeListener)
-
getChangeListeners
public ChangeListener[] getChangeListeners()
Returns an array of all theChangeListener
s added to this JSlider with addChangeListener().- Returns:
- all of the
ChangeListener
s added or an empty array if no listeners have been added - Since:
- 1.4
-
fireStateChanged
protected void fireStateChanged()
Send aChangeEvent
, whose source is thisJSlider
, to allChangeListener
s that have registered interest inChangeEvent
s. This method is called each time aChangeEvent
is received from the model.The event instance is created if necessary, and stored in
changeEvent
.
-
getModel
public BoundedRangeModel getModel()
Returns theBoundedRangeModel
that handles the slider's three fundamental properties: minimum, maximum, value.- Returns:
- the data model for this component
- See Also:
setModel(javax.swing.BoundedRangeModel)
,BoundedRangeModel
-
setModel
public void setModel(BoundedRangeModel newModel)
Sets theBoundedRangeModel
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-null
BoundedRangeModel
to use- See Also:
getModel()
,BoundedRangeModel
-
getValue
public int getValue()
Returns the slider's current value from theBoundedRangeModel
.- Returns:
- the current value of the slider
- See Also:
setValue(int)
,BoundedRangeModel.getValue()
-
setValue
public void setValue(int n)
Sets the slider's current value ton
. 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 theBoundedRangeModel
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:
getValue()
,addChangeListener(javax.swing.event.ChangeListener)
,BoundedRangeModel.setValue(int)
-
getMinimum
public int getMinimum()
Returns the minimum value supported by the slider from theBoundedRangeModel
.- Returns:
- the value of the model's minimum property
- See Also:
setMinimum(int)
,BoundedRangeModel.getMinimum()
-
setMinimum
public void setMinimum(int minimum)
Sets the slider's minimum value tominimum
. 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 theBoundedRangeModel
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:
getMinimum()
,addChangeListener(javax.swing.event.ChangeListener)
,BoundedRangeModel.setMinimum(int)
-
getMaximum
public int getMaximum()
Returns the maximum value supported by the slider from theBoundedRangeModel
.- Returns:
- the value of the model's maximum property
- See Also:
setMaximum(int)
,BoundedRangeModel.getMaximum()
-
setMaximum
public void setMaximum(int maximum)
Sets the slider's maximum value tomaximum
. 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 theBoundedRangeModel
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:
getMaximum()
,addChangeListener(javax.swing.event.ChangeListener)
,BoundedRangeModel.setMaximum(int)
-
getValueIsAdjusting
public boolean getValueIsAdjusting()
Returns thevalueIsAdjusting
property from the model. For details on how this is used, see thesetValueIsAdjusting
documentation.- Returns:
- the value of the model's
valueIsAdjusting
property - See Also:
setValueIsAdjusting(boolean)
-
setValueIsAdjusting
public void setValueIsAdjusting(boolean b)
Sets the model'svalueIsAdjusting
property. Slider look and feel implementations should set this property totrue
when a knob drag begins, and tofalse
when the drag ends.- Parameters:
b
- the new value for thevalueIsAdjusting
property- See Also:
getValueIsAdjusting()
,BoundedRangeModel.setValueIsAdjusting(boolean)
-
getExtent
public int getExtent()
Returns the "extent" from theBoundedRangeModel
. This respresents the range of values "covered" by the knob.- Returns:
- an int representing the extent
- See Also:
setExtent(int)
,BoundedRangeModel.getExtent()
-
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
BoundedRangeModel
) handles any mathematical issues arising from assigning faulty values. See theBoundedRangeModel
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:
getExtent()
,BoundedRangeModel.setExtent(int)
-
getOrientation
public int getOrientation()
Return this slider's vertical or horizontal orientation.- Returns:
SwingConstants.VERTICAL
orSwingConstants.HORIZONTAL
- See Also:
setOrientation(int)
-
setOrientation
public void setOrientation(int orientation)
Set the slider's orientation to eitherSwingConstants.VERTICAL
orSwingConstants.HORIZONTAL
.- Parameters:
orientation
-HORIZONTAL
orVERTICAL
- Throws:
IllegalArgumentException
- if orientation is not one ofVERTICAL
,HORIZONTAL
- See Also:
getOrientation()
-
setFont
public void setFont(Font font)
Sets the font for this component.- Overrides:
setFont
in classJComponent
- Parameters:
font
- the desiredFont
for this component- Since:
- 1.6
- See Also:
Component.getFont()
-
imageUpdate
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
Repaints the component when the image has changed. ThisimageUpdate
method of anImageObserver
is called when more information about an image which had been previously requested using an asynchronous routine such as thedrawImage
method ofGraphics
becomes available. See the definition ofimageUpdate
for more information on this method and its arguments.The
imageUpdate
method ofComponent
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 valuetrue
, 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
, andheight
arguments depends on the value of theinfoflags
argument.- Specified by:
imageUpdate
in interfaceImageObserver
- Overrides:
imageUpdate
in classComponent
- Parameters:
img
- the image being observedinfoflags
- seeimageUpdate
for more informationx
- the x coordinatey
- the y coordinatew
- the widthh
- the height- Returns:
false
if the infoflags indicate that the image is completely loaded;true
otherwise.- Since:
- 1.7
- See Also:
ImageObserver
,Graphics.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 dictionary of what labels to draw at which values.- Returns:
- the
Dictionary
containing labels and where to draw them
-
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
createStandardLabels
method.Once the labels have been set, this method calls
updateLabelUIs()
. Note that the labels are only painted if thepaintLabels
property istrue
.- Parameters:
labels
- newDictionary
of labels, ornull
to remove all labels- See Also:
createStandardLabels(int)
,getLabelTable()
,setPaintLabels(boolean)
-
updateLabelUIs
protected void updateLabelUIs()
Updates the UIs for the labels in the label table by callingupdateUI
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 createStandardLabels(int increment)
Creates aHashtable
of numerical text labels, starting at the slider minimum, and using the increment specified. For example, if you callcreateStandardLabels( 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 intosetLabelTable
, andsetPaintLabels
must be set totrue
.For further details on the makeup of the returned
Hashtable
, see thesetLabelTable
documentation.- Parameters:
increment
- distance between labels in the generated hashtable- Returns:
- a new
Hashtable
of labels - Throws:
IllegalArgumentException
- ifincrement
is less than or equal to zero- See Also:
setLabelTable(java.util.Dictionary)
,setPaintLabels(boolean)
-
createStandardLabels
public Hashtable createStandardLabels(int increment, int start)
Creates aHashtable
of numerical text labels, starting at the starting point specified, and using the increment specified. For example, if you callcreateStandardLabels( 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 intosetLabelTable
, andsetPaintLabels
must be set totrue
.For further details on the makeup of the returned
Hashtable
, see thesetLabelTable
documentation.- Parameters:
increment
- distance between labels in the generated hashtablestart
- value at which the labels will begin- Returns:
- a new
Hashtable
of labels - Throws:
IllegalArgumentException
- ifstart
is out of range, or ifincrement
is less than or equal to zero- See Also:
setLabelTable(java.util.Dictionary)
,setPaintLabels(boolean)
-
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
- See Also:
setInverted(boolean)
-
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'sComponentOrientation
property. Normal (non-inverted) horizontal sliders with aComponentOrientation
value ofLEFT_TO_RIGHT
have their maximum on the right. Normal horizontal sliders with aComponentOrientation
value ofRIGHT_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()
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
- See Also:
setMajorTickSpacing(int)
-
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,
setPaintTicks
must be set totrue
.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
, andgetPaintLabels
returnstrue
, a standard label table will be generated (by callingcreateStandardLabels
) 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 callingsetLabelTable
.- Parameters:
n
- new value for themajorTickSpacing
property- See Also:
getMajorTickSpacing()
,setPaintTicks(boolean)
,setLabelTable(java.util.Dictionary)
,createStandardLabels(int)
-
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
- See Also:
getMinorTickSpacing()
-
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,
setPaintTicks
must be set totrue
.- Parameters:
n
- new value for theminorTickSpacing
property- See Also:
getMinorTickSpacing()
,setPaintTicks(boolean)
-
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(boolean)
-
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 isfalse
.- Parameters:
b
- true to snap the knob to the nearest tick mark- See Also:
getSnapToTicks()
-
getPaintTicks
public boolean getPaintTicks()
Tells if tick marks are to be painted.- Returns:
- true if tick marks are painted, else false
- See Also:
setPaintTicks(boolean)
-
setPaintTicks
public void setPaintTicks(boolean b)
Determines whether tick marks are painted on the slider. By default, this property isfalse
.- Parameters:
b
- whether or not tick marks should be painted- See Also:
getPaintTicks()
-
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
- See Also:
setPaintTrack(boolean)
-
setPaintTrack
public void setPaintTrack(boolean b)
Determines whether the track is painted on the slider. By default, this property istrue
.- Parameters:
b
- whether or not to paint the slider track- See Also:
getPaintTrack()
-
getPaintLabels
public boolean getPaintLabels()
Tells if labels are to be painted.- Returns:
- true if labels are painted, else false
- See Also:
setPaintLabels(boolean)
-
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
> 0
, a standard label table will be generated (by callingcreateStandardLabels
) with labels at the major tick marks. The label table is then set on the slider by callingsetLabelTable
.By default, this property is
false
.- Parameters:
b
- whether or not to paint labels- See Also:
getPaintLabels()
,getLabelTable()
,createStandardLabels(int)
-
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 benull
.- Overrides:
paramString
in classJComponent
- Returns:
- a string representation of this JSlider.
-
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.- Specified by:
getAccessibleContext
in interfaceAccessible
- Overrides:
getAccessibleContext
in classJComponent
- Returns:
- an AccessibleJSlider that serves as the AccessibleContext of this JSlider
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/11/2024 21:20:44 Cette version de la page est en cache (à la date du 21/11/2024 21:20:44) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 29/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/jslider.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.