Class SpinnerValueFactory.DoubleSpinnerValueFactory
- Enclosing class:
SpinnerValueFactory<T>
public static class SpinnerValueFactory.DoubleSpinnerValueFactory extends SpinnerValueFactory<Double>
SpinnerValueFactory implementation designed to iterate through double values. If wrapAround is true, the DoubleSpinnerValueFactory will step through from the maximum value to the minimum value seamlessly; that is, any step up from the maximum value is equal to the same step up from the minimum value (and vice versa). The new value after a step is val = (val + amountToStepBy) % (max - min).
Note that the default converter is implemented simply as shown below, which may be adequate in many cases, but it is important for users to ensure that this suits their needs (and adjust when necessary). The main point to note is that this StringConverter embeds within it a DecimalFormat instance that shows the Double to two decimal places. This is used for both the toString and fromString methods:
setConverter(new StringConverter<Double>() {
private final DecimalFormat df = new DecimalFormat("#.##");
@Override public String toString(Double value) {
// If the specified value is null, return a zero-length String
if (value == null) {
return "";
}
return df.format(value);
}
@Override public Double fromString(String value) {
try {
// If the specified value is null or zero-length, return null
if (value == null) {
return null;
}
value = value.trim();
if (value.length() < 1) {
return null;
}
// Perform the requested parsing
return df.parse(value).doubleValue();
} catch (ParseException ex) {
throw new RuntimeException(ex);
}
}
});
- Since:
- JavaFX 8u40
Nested Class Summary
Nested classes/interfaces declared in class javafx.scene.control.SpinnerValueFactory
SpinnerValueFactory.DoubleSpinnerValueFactory, SpinnerValueFactory.IntegerSpinnerValueFactory, SpinnerValueFactory.ListSpinnerValueFactory<T>
Property Summary
| Type | Property | Description |
|---|---|---|
final DoubleProperty |
amountToStepBy |
Sets the amount to increment or decrement by, per step. |
final DoubleProperty |
max |
Sets the maximum allowable value for this value factory |
final DoubleProperty |
min |
Sets the minimum allowable value for this value factory |
Properties declared in class javafx.scene.control.SpinnerValueFactory
converter, value, wrapAround
Constructor Summary
| Constructor | Description |
|---|---|
DoubleSpinnerValueFactory |
Constructs a new DoubleSpinnerValueFactory that sets the initial value to be equal to the min value, and a default amountToStepBy of one. |
DoubleSpinnerValueFactory |
Constructs a new DoubleSpinnerValueFactory with a default amountToStepBy of one. |
DoubleSpinnerValueFactory |
Constructs a new DoubleSpinnerValueFactory. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
final DoubleProperty |
amountToStepByProperty() |
Sets the amount to increment or decrement by, per step. |
void |
decrement |
Attempts to decrement the value by the given number of steps. |
final double |
getAmountToStepBy() |
Gets the value of the amountToStepBy property. |
final double |
getMax() |
Gets the value of the max property. |
final double |
getMin() |
Gets the value of the min property. |
void |
increment |
Attempts to increment the value by the given number of steps. |
final DoubleProperty |
maxProperty() |
Sets the maximum allowable value for this value factory |
final DoubleProperty |
minProperty() |
Sets the minimum allowable value for this value factory |
final void |
setAmountToStepBy |
Sets the value of the amountToStepBy property. |
final void |
setMax |
Sets the value of the max property. |
final void |
setMin |
Sets the value of the min property. |
Methods declared in class javafx.scene.control.SpinnerValueFactory
converterProperty, getConverter, getValue, isWrapAround, setConverter, setValue, setWrapAround, valueProperty, wrapAroundProperty
Property Details
min
public final DoubleProperty minProperty
- See Also:
max
public final DoubleProperty maxProperty
- See Also:
amountToStepBy
public final DoubleProperty amountToStepByProperty
- See Also:
Constructor Details
DoubleSpinnerValueFactory
public DoubleSpinnerValueFactory(double min, double max)
amountToStepBy of one.- Parameters:
-
min- The minimum allowed double value for the Spinner. -
max- The maximum allowed double value for the Spinner.
DoubleSpinnerValueFactory
public DoubleSpinnerValueFactory(double min, double max, double initialValue)
amountToStepBy of one.- Parameters:
-
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.
DoubleSpinnerValueFactory
public DoubleSpinnerValueFactory(double min, double max, double initialValue, double amountToStepBy)
- Parameters:
-
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.
Method Details
setMin
public final void setMin(double value)
min property.- Property description:
- Sets the minimum allowable value for this value factory
- Parameters:
-
value- the value for theminproperty - See Also:
getMin
public final double getMin()
min property.- Property description:
- Sets the minimum allowable value for this value factory
- Returns:
- the value of the
minproperty - See Also:
minProperty
public final DoubleProperty minProperty()
- Returns:
- the minimum allowable value for this value factory
- See Also:
setMax
public final void setMax(double value)
max property.- Property description:
- Sets the maximum allowable value for this value factory
- Parameters:
-
value- the value for themaxproperty - See Also:
getMax
public final double getMax()
max property.- Property description:
- Sets the maximum allowable value for this value factory
- Returns:
- the value of the
maxproperty - See Also:
maxProperty
public final DoubleProperty maxProperty()
- Returns:
- the maximum allowable value for this value factory
- See Also:
setAmountToStepBy
public final void setAmountToStepBy(double value)
amountToStepBy property.- Property description:
- Sets the amount to increment or decrement by, per step.
- Parameters:
-
value- the value for theamountToStepByproperty - See Also:
getAmountToStepBy
public final double getAmountToStepBy()
amountToStepBy property.- Property description:
- Sets the amount to increment or decrement by, per step.
- Returns:
- the value of the
amountToStepByproperty - See Also:
amountToStepByProperty
public final DoubleProperty amountToStepByProperty()
- Returns:
- the amount to increment or decrement by, per step
- See Also:
decrement
public void decrement(int steps)
value by the given number of steps.- Specified by:
-
decrementin classSpinnerValueFactory<Double> - Parameters:
-
steps- The number of decrements that should be performed on the value. If the number is negative, the call is equivalent to callingSpinnerValueFactory.increment(int)with the absolute value ofsteps.
increment
public void increment(int steps)
value by the given number of steps.- Specified by:
-
incrementin classSpinnerValueFactory<Double> - Parameters:
-
steps- The number of increments that should be performed on the value. If the number is negative, the call is equivalent to callingSpinnerValueFactory.decrement(int)with the absolute number ofsteps.
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.