I want to use a FX8 Spinner control, but I want to bind the source to an IntegerProperty
int MIN = 0;
int MAX = 5000;
int STEP = 500;
IntegerProperty integerProperty = new SimpleIntegerProperty();
Spinner<Integer> spinner = new Spinner<>(MIN, MAX, STEP);
I understand the binding is set via binding to the valueProperty in the Value Factory. However this expects Property<Integer> and I cannot find a way to cast between IntegerProperty and Property<Integer>. 
Obviously the below generates a compiler error:
spinner.getValueFactory().valueProperty().bindBidirectional(integerProperty);
Do I need to manually assign a change listener for both directions? Surely there is a neater solution using the valueProperty, this cannot have been an unforeseen situation.
You can wrap an ObjectProperty:
ObjectProperty<Integer> objectProp = new SimpleObjectProperty<>(MIN);
IntegerProperty integerProperty = IntegerProperty.integerProperty(objectProp);
Spinner<Integer> spinner = new Spinner<>(MIN, MAX, STEP);
spinner.getValueFactory().valueProperty().bindBidirectional(objectProp);
IntegerProperty.integerProperty creates a property that's bidirectionally connected to the property it wraps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With