Class SpinnerValueFactory.DoubleSpinnerValueFactory

java.lang.Object
javafx.scene.control.SpinnerValueFactory<Double>
javafx.scene.control.SpinnerValueFactory.DoubleSpinnerValueFactory
Enclosing class:
SpinnerValueFactory<T>

public static class SpinnerValueFactory.DoubleSpinnerValueFactory extends SpinnerValueFactory<Double>
A 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