If I create an instance of a Spinner using the constructor with arguments, that spinner will not show the given values. But when using a SpinnerValueFactory() and apply it to the spinner, it loads the initial value and sets min,max.
The documentation says:
Spinner(double min, double max, double initialValue, double amountToStepBy)Creates a
Spinnerinstance with the value factory set to be an instance ofSpinnerValueFactory.DoubleSpinnerValueFactory.
So I would expect the constructor to set its own SpinnerValueFactory. My question is, why does that not work? How should one use those constructors?
In order to keep my code better readable and shorter, I would love to only use the constructor without an individual SpinnerValueFactory() for each Spinner (I need a couple of different ones).
What I would expect to work, but which does not: controller.java:
@FXML Spinner<Integer> mySpinner;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
mySpinner = new Spinner(1, 100, 1, 1);
}
What works:
SpinnerValueFactory.IntegerSpinnerValueFactory myFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100, 1, 1);
@FXML Spinner<Integer> mySpinner;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
mySpinner.setValueFactory(myFactory);
}