Converting Integer to ObservableValue in javafx


Question

How to convert Integer To ObservableValue<Integer> in javafx 2.0 and later ?

1
13
11/11/2016 3:12:34 AM

Accepted Answer

We use a ReadOnlyObjectWrapper<>(*integer value*); and store the value in a ObservableValue<Integer> reference.

ObservableValue<Integer> obsInt = new ReadOnlyObjectWrapper<>(intValue);

Update

Starting JavaFX 8, you can also do the following :

ObservableValue<Integer> obsInt = new SimpleIntegerProperty(intValue).asObject();
28
11/11/2016 3:17:39 AM

Another way.

new SimpleIntegerProperty(integer_value).asObject()

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon