T - The type of all values that can be iterated through in the Spinner.
Common types include Integer and String.public class Spinner<T> extends Control
wrapping
and simpler specification of 'infinite' data models (the
SpinnerValueFactory, rather than using a
ObservableList data model like many
other JavaFX UI controls.
A Spinner's sequence value is defined by its
SpinnerValueFactory. The value factory
can be specified as a constructor argument and changed with the
value factory property. SpinnerValueFactory
classes for some common types are provided with JavaFX, including:
SpinnerValueFactory.IntegerSpinnerValueFactorySpinnerValueFactory.DoubleSpinnerValueFactorySpinnerValueFactory.ListSpinnerValueFactoryA Spinner has a TextField child component that is responsible for displaying
and potentially changing the current value of the
Spinner, which is called the editor. By default the
Spinner is non-editable, but input can be accepted if the
editable property is set to true. The Spinner
editor stays in sync with the value factory by listening for changes to the
value property of the value factory.
If the user has changed the value displayed in the editor it is possible for
the Spinner value to differ from that of the editor.
To make sure the model has the same value as the editor, the user must commit
the edit using the Enter key.
SpinnerValueFactory| Modifier and Type | Field and Description |
|---|---|
static String |
STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL
The arrows are placed on the left of the Spinner, pointing horizontally (i.e.
|
static String |
STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL
The arrows are placed on the left of the Spinner, pointing vertically (i.e.
|
static String |
STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL
The arrows are placed on the right of the Spinner, pointing horizontally (i.e.
|
static String |
STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL
The decrement arrow is placed on the left of the Spinner, and the increment on the right.
|
static String |
STYLE_CLASS_SPLIT_ARROWS_VERTICAL
The arrows are placed above and beneath the spinner, stretching to take the entire width.
|
USE_COMPUTED_SIZE, USE_PREF_SIZEBASELINE_OFFSET_SAME_AS_HEIGHT| Constructor and Description |
|---|
Spinner()
Constructs a default Spinner instance, with the default 'spinner' style
class and a non-editable editor.
|
Spinner(double min,
double max,
double initialValue)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.DoubleSpinnerValueFactory. |
Spinner(double min,
double max,
double initialValue,
double amountToStepBy)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.DoubleSpinnerValueFactory. |
Spinner(int min,
int max,
int initialValue)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.IntegerSpinnerValueFactory. |
Spinner(int min,
int max,
int initialValue,
int amountToStepBy)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.IntegerSpinnerValueFactory. |
Spinner(ObservableList<T> items)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.ListSpinnerValueFactory. |
Spinner(SpinnerValueFactory<T> valueFactory)
Creates a Spinner instance with the given value factory set.
|
| Modifier and Type | Method and Description |
|---|---|
protected Skin<?> |
createDefaultSkin()
Create a new instance of the default skin for this control.
|
void |
decrement()
Attempts to decrement the
value factory
by one step, by calling the SpinnerValueFactory.decrement(int)
method with an argument of one. |
void |
decrement(int steps)
Attempts to decrement the
value factory
by the given number of steps, by calling the
SpinnerValueFactory.decrement(int)
method and forwarding the steps argument to it. |
BooleanProperty |
editableProperty() |
ReadOnlyObjectProperty<TextField> |
editorProperty()
The editor used by the Spinner control.
|
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.
|
TextField |
getEditor() |
T |
getValue() |
SpinnerValueFactory<T> |
getValueFactory() |
void |
increment()
Attempts to increment the
value factory
by one step, by calling the SpinnerValueFactory.increment(int)
method with an argument of one. |
void |
increment(int steps)
Attempts to increment the
value factory
by the given number of steps, by calling the
SpinnerValueFactory.increment(int)
method and forwarding the steps argument to it. |
boolean |
isEditable() |
Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
Object... parameters)
*
Accessibility handling *
*
|
void |
setEditable(boolean value) |
void |
setValueFactory(SpinnerValueFactory<T> value) |
ObjectProperty<SpinnerValueFactory<T>> |
valueFactoryProperty() |
ReadOnlyObjectProperty<T> |
valueProperty() |
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getClassCssMetaData, getContextMenu, getControlCssMetaData, getCssMetaData, getSkin, getTooltip, impl_cssGetFocusTraversableInitialValue, impl_processCSS, isResizable, layoutChildren, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipPropertybackgroundProperty, 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, widthPropertygetChildren, getChildrenUnmodifiable, getImpl_traversalEngine, getManagedChildren, getStylesheets, impl_getAllParentStylesheets, impl_processMXNode, impl_traversalEngineProperty, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setImpl_traversalEngine, setNeedsLayout, updateBoundsaccessibleHelpProperty, 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, visiblePropertypublic static final String STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL
public static final String STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL
public static final String STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL
public static final String STYLE_CLASS_SPLIT_ARROWS_VERTICAL
public static final String STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL
public Spinner()
public Spinner(int min,
int max,
int initialValue)
value factory set to be an instance
of SpinnerValueFactory.IntegerSpinnerValueFactory. Note that
if this constructor is called, the only valid generic type for the
Spinner instance is Integer, i.e. Spinner<Integer>.min - The minimum allowed integer value for the Spinner.max - The maximum allowed integer value for the Spinner.initialValue - The value of the Spinner when first instantiated, must
be within the bounds of the min and max arguments, or
else the min value will be used.public Spinner(int min,
int max,
int initialValue,
int amountToStepBy)
value factory set to be an instance
of SpinnerValueFactory.IntegerSpinnerValueFactory. Note that
if this constructor is called, the only valid generic type for the
Spinner instance is Integer, i.e. Spinner<Integer>.min - The minimum allowed integer value for the Spinner.max - The maximum allowed integer value for the Spinner.initialValue - The value of the Spinner when first instantiated, must
be within the bounds of the min and max arguments, or
else the min value will be used.amountToStepBy - The amount to increment or decrement by, per step.public Spinner(double min,
double max,
double initialValue)
value factory set to be an instance
of SpinnerValueFactory.DoubleSpinnerValueFactory. Note that
if this constructor is called, the only valid generic type for the
Spinner instance is Double, i.e. Spinner<Double>.min - The minimum allowed double value for the Spinner.max - The maximum allowed double value for the Spinner.initialValue - The value of the Spinner when first instantiated, must
be within the bounds of the min and max arguments, or
else the min value will be used.public Spinner(double min,
double max,
double initialValue,
double amountToStepBy)
value factory set to be an instance
of SpinnerValueFactory.DoubleSpinnerValueFactory. Note that
if this constructor is called, the only valid generic type for the
Spinner instance is Double, i.e. Spinner<Double>.min - The minimum allowed double value for the Spinner.max - The maximum allowed double value for the Spinner.initialValue - The value of the Spinner when first instantiated, must
be within the bounds of the min and max arguments, or
else the min value will be used.amountToStepBy - The amount to increment or decrement by, per step.public Spinner(ObservableList<T> items)
value factory set to be an instance
of SpinnerValueFactory.ListSpinnerValueFactory. The
Spinner value property will be set to the first
element of the list, if an element exists, or null otherwise.items - A list of items that will be stepped through in the Spinner.public Spinner(SpinnerValueFactory<T> valueFactory)
valueFactory - The value factory to use.public void increment()
value factory
by one step, by calling the SpinnerValueFactory.increment(int)
method with an argument of one. If the value factory is null, an
IllegalStateException is thrown.IllegalStateException - if the value factory returned by
calling getValueFactory() is null.public void increment(int steps)
value factory
by the given number of steps, by calling the
SpinnerValueFactory.increment(int)
method and forwarding the steps argument to it. If the value factory is
null, an IllegalStateException is thrown.steps - The number of increments that should be performed on the value.IllegalStateException - if the value factory returned by
calling getValueFactory() is null.public void decrement()
value factory
by one step, by calling the SpinnerValueFactory.decrement(int)
method with an argument of one. If the value factory is null, an
IllegalStateException is thrown.IllegalStateException - if the value factory returned by
calling getValueFactory() is null.public void decrement(int steps)
value factory
by the given number of steps, by calling the
SpinnerValueFactory.decrement(int)
method and forwarding the steps argument to it. If the value factory is
null, an IllegalStateException is thrown.steps - The number of decrements that should be performed on the value.IllegalStateException - if the value factory returned by
calling getValueFactory() is null.protected Skin<?> createDefaultSkin()
-fx-skin or set explicitly in a sub-class with setSkin(...).createDefaultSkin in class Controlpublic final T getValue()
public final ReadOnlyObjectProperty<T> valueProperty()
public final void setValueFactory(SpinnerValueFactory<T> value)
public final SpinnerValueFactory<T> getValueFactory()
public final ObjectProperty<SpinnerValueFactory<T>> valueFactoryProperty()
public final void setEditable(boolean value)
public final boolean isEditable()
public final BooleanProperty editableProperty()
public final ReadOnlyObjectProperty<TextField> editorProperty()
public final TextField getEditor()
public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)
queryAccessibleAttribute in class Controlattribute - the requested attributeparameters - optional list of parametersAccessibleAttributepublic 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 Controlaction - the action to executeparameters - optional list of parametersAccessibleActionCopyright © 2025. All rights reserved.