You need to set the valueFactory
for the spinner to allow the Spinner
's value to become non-null
. This can be done by directly assigning the property:
<Spinner fx:id="uni" prefHeight="25.0" prefWidth="342.0">
<valueFactory>
<!-- add factory instance creation here -->
</valueFactory>
</Spinner>
by using the appropriate constructor
<Spinner fx:id="uni" prefHeight="25.0" prefWidth="342.0" min="1" max="10" initialValue="4" />
or by "manually" doing it in the initialize
method:
SpinnerValueFactory valueFactory = ...
uni.setValueFactory(valueFactory);
Also you should specify the type parameter for the Spinner
, even if it's a wildcard (Spinner<?>
), see What is a raw type and why shouldn't we use it?
Making an educated guess, you may be looking for something like this:
<fx:define>
<FXCollections fx:factory="observableArrayList" fx:id="unis" />
</fx:define>
<Spinner fx:id="uni" prefHeight="25.0" prefWidth="342.0" items="$unis" />
Controller
@FXML
private Spinner<String> uni;
@FXML
private ObservableList<String> unis;
@Override
public void initialize(URL url, ResourceBundle rb) {
unis.add("Oxford");
unis.add("Harvard");
}