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.IntegerSpinnerValueFactory
SpinnerValueFactory.DoubleSpinnerValueFactory
SpinnerValueFactory.ListSpinnerValueFactory
A 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
Type | Property and Description |
---|---|
BooleanProperty |
editable
The editable property is used to specify whether user input is able to
be typed into the Spinner
editor . |
<any> |
editor
The editor used by the Spinner control.
|
<any> |
initialDelay
The duration that the mouse has to be pressed on an arrow button
before the next value steps.
|
StringProperty |
promptText
The prompt text to display in the
Spinner , or
null if no prompt text is displayed. |
<any> |
repeatDelay
The duration that the mouse has to be pressed for each successive step
after the first value steps.
|
<any> |
valueFactory
The value factory is the model behind the JavaFX Spinner control - without
a value factory installed a Spinner is unusable.
|
<any> |
value
The value property on Spinner is a read-only property, as it is bound to
the SpinnerValueFactory
value property . |
contextMenuProperty, skinClassNameProperty, skinProperty, tooltipProperty
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
DEFAULT_STYLE_CLASS |
private BooleanProperty |
editable
The editable property is used to specify whether user input is able to
be typed into the Spinner
editor . |
private <any> |
editor |
private static <any> |
INITIAL_DELAY
*
Stylesheet Handling *
*
|
private <any> |
initialDelay |
private static <any> |
REPEAT_DELAY |
private <any> |
repeatDelay |
static java.lang.String |
STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL
The arrows are placed on the left of the Spinner, pointing horizontally (i.e.
|
static java.lang.String |
STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL
The arrows are placed on the left of the Spinner, pointing vertically (i.e.
|
static java.lang.String |
STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL
The arrows are placed on the right of the Spinner, pointing horizontally (i.e.
|
static java.lang.String |
STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL
The decrement arrow is placed on the left of the Spinner, and the increment on the right.
|
static java.lang.String |
STYLE_CLASS_SPLIT_ARROWS_VERTICAL
The arrows are placed above and beneath the spinner, stretching to take the entire width.
|
private static java.util.List<<any>> |
STYLEABLES |
private TextField |
textField |
private <any> |
value
The value property on Spinner is a read-only property, as it is bound to
the SpinnerValueFactory
value property . |
private <any> |
valueFactory
The value factory is the model behind the JavaFX Spinner control - without
a value factory installed a Spinner is unusable.
|
Constructor and Description |
---|
Spinner()
Constructs a default Spinner instance, with the default 'spinner' style
class and a non-editable editor.
|
Spinner(<any> items)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.ListSpinnerValueFactory . |
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(java.time.LocalDate min,
java.time.LocalDate max,
java.time.LocalDate initialValue)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.LocalDateSpinnerValueFactory . |
Spinner(java.time.LocalDate min,
java.time.LocalDate max,
java.time.LocalDate initialValue,
long amountToStepBy,
java.time.temporal.TemporalUnit temporalUnit)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.LocalDateSpinnerValueFactory . |
Spinner(java.time.LocalTime min,
java.time.LocalTime max,
java.time.LocalTime initialValue)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.LocalTimeSpinnerValueFactory . |
Spinner(java.time.LocalTime min,
java.time.LocalTime max,
java.time.LocalTime initialValue,
long amountToStepBy,
java.time.temporal.TemporalUnit temporalUnit)
Creates a Spinner instance with the
value factory set to be an instance
of SpinnerValueFactory.LocalTimeSpinnerValueFactory . |
Modifier and Type | Method and Description |
---|---|
void |
cancelEdit()
|
void |
commitValue()
|
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()
The editable property is used to specify whether user input is able to
be typed into the Spinner
editor . |
<any> |
editorProperty()
The editor used by the Spinner control.
|
void |
executeAccessibleAction(AccessibleAction action,
java.lang.Object... parameters) |
static java.util.List<<any>> |
getClassCssMetaData() |
java.util.List<<any>> |
getControlCssMetaData() |
TextField |
getEditor()
Gets the value of the property editor.
|
Duration |
getInitialDelay()
Gets the value of the property initialDelay.
|
java.lang.String |
getPromptText()
Gets the value of the property promptText.
|
Duration |
getRepeatDelay()
Gets the value of the property repeatDelay.
|
T |
getValue()
Gets the value of the property value.
|
SpinnerValueFactory<T> |
getValueFactory()
Gets the value of the property valueFactory.
|
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. |
<any> |
initialDelayProperty()
The duration that the mouse has to be pressed on an arrow button
before the next value steps.
|
boolean |
isEditable()
Gets the value of the property editable.
|
StringProperty |
promptTextProperty()
The prompt text to display in the
Spinner , or
null if no prompt text is displayed. |
java.lang.Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
java.lang.Object... parameters) |
<any> |
repeatDelayProperty()
The duration that the mouse has to be pressed for each successive step
after the first value steps.
|
void |
setEditable(boolean value)
Sets the value of the property editable.
|
void |
setInitialDelay(Duration value)
Sets the value of the property initialDelay.
|
void |
setPromptText(java.lang.String value)
Sets the value of the property promptText.
|
void |
setRepeatDelay(Duration value)
Sets the value of the property repeatDelay.
|
private void |
setText(T value)
*
Implementation *
*
|
void |
setValueFactory(SpinnerValueFactory<T> value)
Sets the value of the property valueFactory.
|
<any> |
valueFactoryProperty()
The value factory is the model behind the JavaFX Spinner control - without
a value factory installed a Spinner is unusable.
|
<any> |
valueProperty()
The value property on Spinner is a read-only property, as it is bound to
the SpinnerValueFactory
value property . |
(package private) static java.math.BigDecimal |
wrapValue(java.math.BigDecimal value,
java.math.BigDecimal min,
java.math.BigDecimal max) |
(package private) static int |
wrapValue(int value,
int min,
int max) |
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getControlChildren, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, loadSkinClass, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipProperty
public final <any> valueProperty
value property
. Should the
value factory
change, this value property
will be unbound from the old value factory and bound to the new one.
If developers wish to modify the value property, they may do so with code in the following form:
Object newValue = ...;
spinner.getValueFactory().setValue(newValue);
getValue()
public final <any> valueFactoryProperty
value
,Incrementing
and decrementing
the
value, with one or more steps per call,Converting
text input
from the user (via the Spinner editor
,objects to user-readable strings
for display on screenpublic final BooleanProperty editableProperty
editor
. If editable
is true, user input will be received once the user types and presses
the Enter key. At this point the input is passed to the
SpinnerValueFactory converter
javafx.util.StringConverter#fromString(String)
method.
The returned value from this call (of type T) is then sent to the
SpinnerValueFactory.setValue(Object)
method. If the value
is valid, it will remain as the value. If it is invalid, the value factory
will need to react accordingly and back out this change.isEditable()
,
setEditable(boolean)
public final <any> editorProperty
getEditor()
public final StringProperty promptTextProperty
Spinner
, or
null
if no prompt text is displayed.getPromptText()
,
setPromptText(String)
public final <any> initialDelayProperty
repeat delay
.getInitialDelay()
,
setInitialDelay(Duration)
public final <any> repeatDelayProperty
initial delay
.getRepeatDelay()
,
setRepeatDelay(Duration)
private static final java.lang.String DEFAULT_STYLE_CLASS
public static final java.lang.String STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL
public static final java.lang.String STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL
public static final java.lang.String STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL
public static final java.lang.String STYLE_CLASS_SPLIT_ARROWS_VERTICAL
public static final java.lang.String STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL
private <any> value
value property
. Should the
value factory
change, this value property
will be unbound from the old value factory and bound to the new one.
If developers wish to modify the value property, they may do so with code in the following form:
Object newValue = ...;
spinner.getValueFactory().setValue(newValue);
private <any> valueFactory
value
,Incrementing
and decrementing
the
value, with one or more steps per call,Converting
text input
from the user (via the Spinner editor
,objects to user-readable strings
for display on screenprivate BooleanProperty editable
editor
. If editable
is true, user input will be received once the user types and presses
the Enter key. At this point the input is passed to the
SpinnerValueFactory converter
javafx.util.StringConverter#fromString(String)
method.
The returned value from this call (of type T) is then sent to the
SpinnerValueFactory.setValue(Object)
method. If the value
is valid, it will remain as the value. If it is invalid, the value factory
will need to react accordingly and back out this change.private TextField textField
private <any> editor
private final <any> initialDelay
private final <any> repeatDelay
private static final <any> INITIAL_DELAY
private static final <any> REPEAT_DELAY
private static final java.util.List<<any>> STYLEABLES
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.Spinner(java.time.LocalDate min, java.time.LocalDate max, java.time.LocalDate initialValue)
value factory
set to be an instance
of SpinnerValueFactory.LocalDateSpinnerValueFactory
. Note that
if this constructor is called, the only valid generic type for the
Spinner instance is LocalDate, i.e. Spinner<LocalDate>.min
- The minimum allowed LocalDate value for the Spinner.max
- The maximum allowed LocalDate 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.Spinner(java.time.LocalDate min, java.time.LocalDate max, java.time.LocalDate initialValue, long amountToStepBy, java.time.temporal.TemporalUnit temporalUnit)
value factory
set to be an instance
of SpinnerValueFactory.LocalDateSpinnerValueFactory
. Note that
if this constructor is called, the only valid generic type for the
Spinner instance is LocalDate, i.e. Spinner<LocalDate>.min
- The minimum allowed LocalDate value for the Spinner.max
- The maximum allowed LocalDate 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.temporalUnit
- The size of each step (e.g. day, week, month, year, etc).Spinner(java.time.LocalTime min, java.time.LocalTime max, java.time.LocalTime initialValue)
value factory
set to be an instance
of SpinnerValueFactory.LocalTimeSpinnerValueFactory
. Note that
if this constructor is called, the only valid generic type for the
Spinner instance is LocalTime, i.e. Spinner<LocalTime>.min
- The minimum allowed LocalTime value for the Spinner.max
- The maximum allowed LocalTime 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.Spinner(java.time.LocalTime min, java.time.LocalTime max, java.time.LocalTime initialValue, long amountToStepBy, java.time.temporal.TemporalUnit temporalUnit)
value factory
set to be an instance
of SpinnerValueFactory.LocalTimeSpinnerValueFactory
. Note that
if this constructor is called, the only valid generic type for the
Spinner instance is LocalTime, i.e. Spinner<LocalTime>.min
- The minimum allowed LocalTime value for the Spinner.max
- The maximum allowed LocalTime 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.temporalUnit
- The size of each step (e.g. hour, minute, second, etc).public Spinner(<any> 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 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.java.lang.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.java.lang.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.java.lang.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.java.lang.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 Control
public final void commitValue()
editable
, calling this method will attempt to
commit the current text and convert it to a value
.public final void cancelEdit()
editable
, calling this method will attempt to
replace the editor text with the last committed value
.public final T getValue()
public final <any> valueProperty()
value property
. Should the
value factory
change, this value property
will be unbound from the old value factory and bound to the new one.
If developers wish to modify the value property, they may do so with code in the following form:
Object newValue = ...;
spinner.getValueFactory().setValue(newValue);
getValue()
public final void setValueFactory(SpinnerValueFactory<T> value)
public final SpinnerValueFactory<T> getValueFactory()
public final <any> valueFactoryProperty()
value
,Incrementing
and decrementing
the
value, with one or more steps per call,Converting
text input
from the user (via the Spinner editor
,objects to user-readable strings
for display on screenpublic final void setEditable(boolean value)
public final boolean isEditable()
public final BooleanProperty editableProperty()
editor
. If editable
is true, user input will be received once the user types and presses
the Enter key. At this point the input is passed to the
SpinnerValueFactory converter
javafx.util.StringConverter#fromString(String)
method.
The returned value from this call (of type T) is then sent to the
SpinnerValueFactory.setValue(Object)
method. If the value
is valid, it will remain as the value. If it is invalid, the value factory
will need to react accordingly and back out this change.isEditable()
,
setEditable(boolean)
public final <any> editorProperty()
getEditor()
public final TextField getEditor()
public final StringProperty promptTextProperty()
Spinner
, or
null
if no prompt text is displayed.getPromptText()
,
setPromptText(String)
public final java.lang.String getPromptText()
public final void setPromptText(java.lang.String value)
public final <any> initialDelayProperty()
repeat delay
.getInitialDelay()
,
setInitialDelay(Duration)
public final void setInitialDelay(Duration value)
public final Duration getInitialDelay()
public final <any> repeatDelayProperty()
initial delay
.getRepeatDelay()
,
setRepeatDelay(Duration)
public final void setRepeatDelay(Duration value)
public final Duration getRepeatDelay()
public static java.util.List<<any>> getClassCssMetaData()
public java.util.List<<any>> getControlCssMetaData()
getControlCssMetaData
in class Control
private void setText(T value)
static int wrapValue(int value, int min, int max)
static java.math.BigDecimal wrapValue(java.math.BigDecimal value, java.math.BigDecimal min, java.math.BigDecimal max)
public java.lang.Object queryAccessibleAttribute(AccessibleAttribute attribute, java.lang.Object... parameters)
queryAccessibleAttribute
in class Control
public void executeAccessibleAction(AccessibleAction action, java.lang.Object... parameters)
executeAccessibleAction
in class Control