Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the value of a JavaFX Spinner?

Tags:

java

javafx

I'm wondering how to set the value of a JavaFX Spinner, as I haven't been able to figure it out.

I know with Swing you can just use spinner#setValue but it seems to be different with JavaFX.

@FXML
private Spinner<Integer> spinner;
like image 473
Matt Avatar asked Aug 07 '16 04:08

Matt


2 Answers

spinner.getValueFactory().setValue(...);
like image 137
James_D Avatar answered Oct 23 '22 03:10

James_D


Just in addition to James_D's answer, an extract of the JavaDoc of the value attribute of the Spinner class:

The value property on Spinner is a read-only property, as it is bound to the SpinnerValueFactory 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 ollowing form:

Object newValue = ...; spinner.getValueFactory().setValue(newValue);

like image 36
Fred Danna Avatar answered Oct 23 '22 02:10

Fred Danna