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);
Modifier and Type | Class and Description |
---|---|
private static class |
Slider.StyleableProperties |
Modifier and Type | Field and Description |
---|---|
private DoubleProperty |
blockIncrement
The amount by which to adjust the slider if the track of the slider is
clicked.
|
private static java.lang.String |
DEFAULT_STYLE_CLASS
*
Stylesheet Handling *
*
|
private static PseudoClass |
HORIZONTAL_PSEUDOCLASS_STATE |
private ObjectProperty<StringConverter<java.lang.Double>> |
labelFormatter
A function for formatting the label for a major tick.
|
private DoubleProperty |
majorTickUnit
The unit distance between major tick marks.
|
private DoubleProperty |
max
The maximum value represented by this Slider.
|
private DoubleProperty |
min
The minimum value represented by this Slider.
|
private IntegerProperty |
minorTickCount
The number of minor ticks to place between any two major ticks.
|
private ObjectProperty<Orientation> |
orientation
The orientation of the
Slider can either be horizontal
or vertical. |
private BooleanProperty |
showTickLabels
Indicates that the labels for tick marks should be shown.
|
private BooleanProperty |
showTickMarks
Specifies whether the
Skin implementation should show tick marks. |
private BooleanProperty |
snapToTicks
Indicates whether the
value of the Slider should always
be aligned with the tick marks. |
private DoubleProperty |
value
The current value represented by this Slider.
|
private BooleanProperty |
valueChanging
When true, indicates the current value of this Slider is changing.
|
private static PseudoClass |
VERTICAL_PSEUDOCLASS_STATE |
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 . |
private void |
adjustValues()
Ensures that min is always < max, that value is always
somewhere between the two, and that if snapToTicks is set then the
value will always be set to align with a tick mark.
|
DoubleProperty |
blockIncrementProperty() |
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,
java.lang.Object... parameters)
This method is called by the assistive technology to request the action
indicated by the argument should be executed.
|
double |
getBlockIncrement() |
static java.util.List<CssMetaData<? extends Styleable,?>> |
getClassCssMetaData() |
protected java.util.List<CssMetaData<? extends Styleable,?>> |
getControlCssMetaData()
Deprecated.
This is an experimental API that is not intended for general use and is subject to change in future versions
|
StringConverter<java.lang.Double> |
getLabelFormatter() |
double |
getMajorTickUnit() |
double |
getMax() |
double |
getMin() |
int |
getMinorTickCount() |
Orientation |
getOrientation() |
double |
getValue() |
void |
increment()
Increments the value by
blockIncrement , bounded by max. |
private void |
initialize() |
boolean |
isShowTickLabels() |
boolean |
isShowTickMarks() |
boolean |
isSnapToTicks() |
boolean |
isValueChanging() |
ObjectProperty<StringConverter<java.lang.Double>> |
labelFormatterProperty() |
DoubleProperty |
majorTickUnitProperty() |
DoubleProperty |
maxProperty() |
IntegerProperty |
minorTickCountProperty() |
DoubleProperty |
minProperty() |
ObjectProperty<Orientation> |
orientationProperty() |
java.lang.Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
java.lang.Object... parameters)
*
Accessibility handling *
*
|
void |
setBlockIncrement(double value) |
void |
setLabelFormatter(StringConverter<java.lang.Double> value) |
void |
setMajorTickUnit(double value) |
void |
setMax(double value) |
void |
setMin(double value) |
void |
setMinorTickCount(int value) |
void |
setOrientation(Orientation value) |
void |
setShowTickLabels(boolean value) |
void |
setShowTickMarks(boolean value) |
void |
setSnapToTicks(boolean value) |
void |
setValue(double value) |
void |
setValueChanging(boolean value) |
BooleanProperty |
showTickLabelsProperty() |
BooleanProperty |
showTickMarksProperty() |
BooleanProperty |
snapToTicksProperty() |
private double |
snapValueToTicks(double val)
Utility function which, given the specified value, will position it
either aligned with a tick, or simply clamp between min & max value,
depending on whether snapToTicks is set.
|
BooleanProperty |
valueChangingProperty() |
DoubleProperty |
valueProperty() |
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getControlChildren, getCssMetaData, getSkin, getTooltip, impl_cssGetFocusTraversableInitialValue, impl_processCSS, isResizable, layoutChildren, loadSkinClass, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipProperty
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, impl_computeContains, impl_computeGeomBounds, impl_computeLayoutBounds, impl_createPeer, impl_notifyLayoutBoundsChanged, impl_pickNodeLocal, impl_updatePeer, 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, getImpl_traversalEngine, getManagedChildren, getStylesheets, impl_getAllParentStylesheets, impl_processMXNode, impl_traversalEngineProperty, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setImpl_traversalEngine, setNeedsLayout, updateBounds
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, containsBounds, 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, impl_clearDirty, impl_computeIntersects, impl_cssGetCursorInitialValue, impl_findStyles, impl_geomChanged, impl_getLeafTransform, impl_getMatchingStyles, impl_getPeer, impl_getPivotX, impl_getPivotY, impl_getPivotZ, impl_getStyleMap, impl_hasTransforms, impl_intersects, impl_intersectsBounds, impl_isDirty, impl_isDirtyEmpty, impl_isShowMnemonics, impl_isTreeVisible, impl_layoutBoundsChanged, impl_markDirty, impl_pickNode, impl_processCSS, impl_reapplyCSS, impl_setShowMnemonics, impl_setStyleMap, impl_showMnemonicsProperty, impl_syncPeer, impl_transformsChanged, impl_traverse, impl_treeVisibleProperty, 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
private DoubleProperty max
min
.private DoubleProperty min
max
.private DoubleProperty value
private BooleanProperty valueChanging
private ObjectProperty<Orientation> orientation
Slider
can either be horizontal
or vertical.private BooleanProperty showTickLabels
Skin
implementation will only show labels if
showTickMarks
is also true.private BooleanProperty showTickMarks
Skin
implementation should show tick marks.private DoubleProperty majorTickUnit
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.
private IntegerProperty minorTickCount
private BooleanProperty snapToTicks
value
of the Slider
should always
be aligned with the tick marks. This is honored even if the tick marks
are not shown.private ObjectProperty<StringConverter<java.lang.Double>> labelFormatter
Skin
implementation.private DoubleProperty blockIncrement
snapToTicks
is true then the nearest tick mark to the adjusted
value will be used.private static final java.lang.String DEFAULT_STYLE_CLASS
private static final PseudoClass VERTICAL_PSEUDOCLASS_STATE
private static final PseudoClass HORIZONTAL_PSEUDOCLASS_STATE
public Slider()
public Slider(double min, double max, double value)
min
- Slider minimum valuemax
- Slider maximum valuevalue
- Slider current valueprivate void initialize()
public final void setMax(double value)
public final double getMax()
public final DoubleProperty maxProperty()
public final void setMin(double value)
public final double getMin()
public final DoubleProperty minProperty()
public final void setValue(double value)
public final double getValue()
public final DoubleProperty valueProperty()
public final void setValueChanging(boolean value)
public final boolean isValueChanging()
public final BooleanProperty valueChangingProperty()
public final void setOrientation(Orientation value)
public final Orientation getOrientation()
public final ObjectProperty<Orientation> orientationProperty()
public final void setShowTickLabels(boolean value)
public final boolean isShowTickLabels()
public final BooleanProperty showTickLabelsProperty()
public final void setShowTickMarks(boolean value)
public final boolean isShowTickMarks()
public final BooleanProperty showTickMarksProperty()
public final void setMajorTickUnit(double value)
public final double getMajorTickUnit()
public final DoubleProperty majorTickUnitProperty()
public final void setMinorTickCount(int value)
public final int getMinorTickCount()
public final IntegerProperty minorTickCountProperty()
public final void setSnapToTicks(boolean value)
public final boolean isSnapToTicks()
public final BooleanProperty snapToTicksProperty()
public final void setLabelFormatter(StringConverter<java.lang.Double> value)
public final StringConverter<java.lang.Double> getLabelFormatter()
public final ObjectProperty<StringConverter<java.lang.Double>> labelFormatterProperty()
public final void setBlockIncrement(double value)
public final double getBlockIncrement()
public final DoubleProperty blockIncrementProperty()
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.private void adjustValues()
private double snapValueToTicks(double val)
protected Skin<?> createDefaultSkin()
-fx-skin
or set explicitly in a sub-class with setSkin(...)
.createDefaultSkin
in class Control
public static java.util.List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
@Deprecated protected java.util.List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
getControlCssMetaData
in class Control
public java.lang.Object queryAccessibleAttribute(AccessibleAttribute attribute, java.lang.Object... parameters)
queryAccessibleAttribute
in class Control
attribute
- the requested attributeparameters
- optional list of parametersAccessibleAttribute
public void executeAccessibleAction(AccessibleAction action, java.lang.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