public class Slider extends Control
The three fundamental variables of the slider are min
,
max
, and value
. The value
should always
be a number within the range defined by min
and
max
. min
should always be less than or equal to
max
(although a slider who's min
and
max
are equal is a degenerate case that makes no sense).
min
defaults to 0, whereas max
defaults to 100.
This first example creates a slider who's range, or span, goes from 0 to 1, and who's value defaults to .5:
import javafx.scene.control.Slider; Slider slider = new Slider(0, 1, 0.5);
This next example shows a slider with customized tick marks and tick mark labels, which also spans from 0 to 1:
import javafx.scene.control.Slider; Slider slider = new Slider(0, 1, 0.5); slider.setShowTickMarks(true); slider.setShowTickLabels(true); slider.setMajorTickUnit(0.25f); slider.setBlockIncrement(0.1f);
Type | Property and Description |
---|---|
DoubleProperty |
blockIncrement
The amount by which to adjust the slider if the track of the slider is
clicked.
|
ObjectProperty<StringConverter<Double>> |
labelFormatter
A function for formatting the label for a major tick.
|
DoubleProperty |
majorTickUnit
The unit distance between major tick marks.
|
DoubleProperty |
max
The maximum value represented by this Slider.
|
IntegerProperty |
minorTickCount
The number of minor ticks to place between any two major ticks.
|
DoubleProperty |
min
The minimum value represented by this Slider.
|
ObjectProperty<Orientation> |
orientation
The orientation of the
Slider can either be horizontal
or vertical. |
BooleanProperty |
showTickLabels
Indicates that the labels for tick marks should be shown.
|
BooleanProperty |
showTickMarks
Specifies whether the
Skin implementation should show tick marks. |
BooleanProperty |
snapToTicks
Indicates whether the
value of the Slider should always
be aligned with the tick marks. |
BooleanProperty |
valueChanging
When true, indicates the current value of this Slider is changing.
|
DoubleProperty |
value
The current value represented by this Slider.
|
contextMenu, skin, tooltip
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
needsLayout
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, visible
USE_COMPUTED_SIZE, USE_PREF_SIZE
BASELINE_OFFSET_SAME_AS_HEIGHT
Constructor and Description |
---|
Slider()
Creates a default Slider instance.
|
Slider(double min,
double max,
double value)
Constructs a Slider control with the specified slider min, max and current value values.
|
Modifier and Type | Method and Description |
---|---|
void |
adjustValue(double newValue)
Adjusts
value to match newValue . |
DoubleProperty |
blockIncrementProperty()
The amount by which to adjust the slider if the track of the slider is
clicked.
|
protected Skin<?> |
createDefaultSkin()
Create a new instance of the default skin for this control.
|
void |
decrement()
Decrements the value by
blockIncrement , bounded by max. |
void |
executeAccessibleAction(AccessibleAction action,
Object... parameters)
This method is called by the assistive technology to request the action
indicated by the argument should be executed.
|
double |
getBlockIncrement()
Gets the value of the property blockIncrement.
|
static List<CssMetaData<? extends Styleable,?>> |
getClassCssMetaData() |
StringConverter<Double> |
getLabelFormatter()
Gets the value of the property labelFormatter.
|
double |
getMajorTickUnit()
Gets the value of the property majorTickUnit.
|
double |
getMax()
Gets the value of the property max.
|
double |
getMin()
Gets the value of the property min.
|
int |
getMinorTickCount()
Gets the value of the property minorTickCount.
|
Orientation |
getOrientation()
Gets the value of the property orientation.
|
double |
getValue()
Gets the value of the property value.
|
void |
increment()
Increments the value by
blockIncrement , bounded by max. |
boolean |
isShowTickLabels()
Gets the value of the property showTickLabels.
|
boolean |
isShowTickMarks()
Gets the value of the property showTickMarks.
|
boolean |
isSnapToTicks()
Gets the value of the property snapToTicks.
|
boolean |
isValueChanging()
Gets the value of the property valueChanging.
|
ObjectProperty<StringConverter<Double>> |
labelFormatterProperty()
A function for formatting the label for a major tick.
|
DoubleProperty |
majorTickUnitProperty()
The unit distance between major tick marks.
|
DoubleProperty |
maxProperty()
The maximum value represented by this Slider.
|
IntegerProperty |
minorTickCountProperty()
The number of minor ticks to place between any two major ticks.
|
DoubleProperty |
minProperty()
The minimum value represented by this Slider.
|
ObjectProperty<Orientation> |
orientationProperty()
The orientation of the
Slider can either be horizontal
or vertical. |
Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
Object... parameters)
*
Accessibility handling *
*
|
void |
setBlockIncrement(double value)
Sets the value of the property blockIncrement.
|
void |
setLabelFormatter(StringConverter<Double> value)
Sets the value of the property labelFormatter.
|
void |
setMajorTickUnit(double value)
Sets the value of the property majorTickUnit.
|
void |
setMax(double value)
Sets the value of the property max.
|
void |
setMin(double value)
Sets the value of the property min.
|
void |
setMinorTickCount(int value)
Sets the value of the property minorTickCount.
|
void |
setOrientation(Orientation value)
Sets the value of the property orientation.
|
void |
setShowTickLabels(boolean value)
Sets the value of the property showTickLabels.
|
void |
setShowTickMarks(boolean value)
Sets the value of the property showTickMarks.
|
void |
setSnapToTicks(boolean value)
Sets the value of the property snapToTicks.
|
void |
setValue(double value)
Sets the value of the property value.
|
void |
setValueChanging(boolean value)
Sets the value of the property valueChanging.
|
BooleanProperty |
showTickLabelsProperty()
Indicates that the labels for tick marks should be shown.
|
BooleanProperty |
showTickMarksProperty()
Specifies whether the
Skin implementation should show tick marks. |
BooleanProperty |
snapToTicksProperty()
Indicates whether the
value of the Slider should always
be aligned with the tick marks. |
BooleanProperty |
valueChangingProperty()
When true, indicates the current value of this Slider is changing.
|
DoubleProperty |
valueProperty()
The current value represented by this Slider.
|
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getCssMetaData, getSkin, getTooltip, isResizable, layoutChildren, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapSize, snapSpace, snapToPixelProperty, widthProperty
getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, visibleProperty
public final DoubleProperty maxProperty
min
.getMax()
,
setMax(double)
public final DoubleProperty minProperty
max
.getMin()
,
setMin(double)
public final DoubleProperty valueProperty
min
and max
,
inclusive. If it is ever out of bounds either due to min
or
max
changing or due to itself being changed, then it will
be clamped to always remain valid.getValue()
,
setValue(double)
public final BooleanProperty valueChangingProperty
isValueChanging()
,
setValueChanging(boolean)
public final ObjectProperty<Orientation> orientationProperty
Slider
can either be horizontal
or vertical.getOrientation()
,
setOrientation(Orientation)
public final BooleanProperty showTickLabelsProperty
Skin
implementation will only show labels if
showTickMarks
is also true.isShowTickLabels()
,
setShowTickLabels(boolean)
public final BooleanProperty showTickMarksProperty
Skin
implementation should show tick marks.isShowTickMarks()
,
setShowTickMarks(boolean)
public final DoubleProperty majorTickUnitProperty
min
is 0 and the max
is 100 and the
majorTickUnit
is 25, then there would be 5 tick marks: one at
position 0, one at position 25, one at position 50, one at position
75, and a final one at position 100.
This value should be positive and should be a value less than the span. Out of range values are essentially the same as disabling tick marks.
getMajorTickUnit()
,
setMajorTickUnit(double)
public final IntegerProperty minorTickCountProperty
getMinorTickCount()
,
setMinorTickCount(int)
public final BooleanProperty snapToTicksProperty
value
of the Slider
should always
be aligned with the tick marks. This is honored even if the tick marks
are not shown.isSnapToTicks()
,
setSnapToTicks(boolean)
public final ObjectProperty<StringConverter<Double>> labelFormatterProperty
Skin
implementation.public final DoubleProperty blockIncrementProperty
snapToTicks
is true then the nearest tick mark to the adjusted
value will be used.getBlockIncrement()
,
setBlockIncrement(double)
public Slider()
public Slider(double min, double max, double value)
min
- Slider minimum valuemax
- Slider maximum valuevalue
- Slider current valuepublic final void setMax(double value)
min
.public final double getMax()
min
.public final DoubleProperty maxProperty()
min
.getMax()
,
setMax(double)
public final void setMin(double value)
max
.public final double getMin()
max
.public final DoubleProperty minProperty()
max
.getMin()
,
setMin(double)
public final void setValue(double value)
public final double getValue()
public final DoubleProperty valueProperty()
min
and max
,
inclusive. If it is ever out of bounds either due to min
or
max
changing or due to itself being changed, then it will
be clamped to always remain valid.getValue()
,
setValue(double)
public final void setValueChanging(boolean value)
public final boolean isValueChanging()
public final BooleanProperty valueChangingProperty()
isValueChanging()
,
setValueChanging(boolean)
public final void setOrientation(Orientation value)
Slider
can either be horizontal
or vertical.public final Orientation getOrientation()
Slider
can either be horizontal
or vertical.public final ObjectProperty<Orientation> orientationProperty()
Slider
can either be horizontal
or vertical.getOrientation()
,
setOrientation(Orientation)
public final void setShowTickLabels(boolean value)
Skin
implementation will only show labels if
showTickMarks
is also true.public final boolean isShowTickLabels()
Skin
implementation will only show labels if
showTickMarks
is also true.public final BooleanProperty showTickLabelsProperty()
Skin
implementation will only show labels if
showTickMarks
is also true.isShowTickLabels()
,
setShowTickLabels(boolean)
public final void setShowTickMarks(boolean value)
Skin
implementation should show tick marks.public final boolean isShowTickMarks()
Skin
implementation should show tick marks.public final BooleanProperty showTickMarksProperty()
Skin
implementation should show tick marks.isShowTickMarks()
,
setShowTickMarks(boolean)
public final void setMajorTickUnit(double value)
min
is 0 and the max
is 100 and the
majorTickUnit
is 25, then there would be 5 tick marks: one at
position 0, one at position 25, one at position 50, one at position
75, and a final one at position 100.
This value should be positive and should be a value less than the span. Out of range values are essentially the same as disabling tick marks.
public final double getMajorTickUnit()
min
is 0 and the max
is 100 and the
majorTickUnit
is 25, then there would be 5 tick marks: one at
position 0, one at position 25, one at position 50, one at position
75, and a final one at position 100.
This value should be positive and should be a value less than the span. Out of range values are essentially the same as disabling tick marks.
public final DoubleProperty majorTickUnitProperty()
min
is 0 and the max
is 100 and the
majorTickUnit
is 25, then there would be 5 tick marks: one at
position 0, one at position 25, one at position 50, one at position
75, and a final one at position 100.
This value should be positive and should be a value less than the span. Out of range values are essentially the same as disabling tick marks.
getMajorTickUnit()
,
setMajorTickUnit(double)
public final void setMinorTickCount(int value)
public final int getMinorTickCount()
public final IntegerProperty minorTickCountProperty()
getMinorTickCount()
,
setMinorTickCount(int)
public final void setSnapToTicks(boolean value)
value
of the Slider
should always
be aligned with the tick marks. This is honored even if the tick marks
are not shown.public final boolean isSnapToTicks()
value
of the Slider
should always
be aligned with the tick marks. This is honored even if the tick marks
are not shown.public final BooleanProperty snapToTicksProperty()
value
of the Slider
should always
be aligned with the tick marks. This is honored even if the tick marks
are not shown.isSnapToTicks()
,
setSnapToTicks(boolean)
public final void setLabelFormatter(StringConverter<Double> value)
Skin
implementation.public final StringConverter<Double> getLabelFormatter()
Skin
implementation.public final ObjectProperty<StringConverter<Double>> labelFormatterProperty()
Skin
implementation.public final void setBlockIncrement(double value)
snapToTicks
is true then the nearest tick mark to the adjusted
value will be used.public final double getBlockIncrement()
snapToTicks
is true then the nearest tick mark to the adjusted
value will be used.public final DoubleProperty blockIncrementProperty()
snapToTicks
is true then the nearest tick mark to the adjusted
value will be used.getBlockIncrement()
,
setBlockIncrement(double)
public void adjustValue(double newValue)
value
to match newValue
. The
value
is the actual amount between the
min
and max
. This function
also takes into account snapToTicks
, which
is the main difference between adjustValue and setValue. It also ensures
that the value is some valid number between min and max.public void increment()
blockIncrement
, bounded by max. If the
max is less than or equal to the min, then this method does nothing.public void decrement()
blockIncrement
, bounded by max. If the
max is less than or equal to the min, then this method does nothing.protected Skin<?> createDefaultSkin()
-fx-skin
or set explicitly in a sub-class with setSkin(...)
.createDefaultSkin
in class Control
public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)
queryAccessibleAttribute
in class Control
attribute
- the requested attributeparameters
- optional list of parametersAccessibleAttribute
public void executeAccessibleAction(AccessibleAction action, Object... parameters)
Node
This method is commonly overridden by subclasses to implement
action that are required for a specific role.
If a particular action is not handled, the super class implementation
must be called.
executeAccessibleAction
in class Control
action
- the action to executeparameters
- optional list of parametersAccessibleAction
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2008, 2017, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.