Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Integer to ObservableValue<Integer> in javafx

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

like image 875
ItachiUchiha Avatar asked Jan 19 '13 09:01

ItachiUchiha


2 Answers

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();
like image 124
ItachiUchiha Avatar answered Oct 03 '22 01:10

ItachiUchiha


Another way.

new SimpleIntegerProperty(integer_value).asObject()
like image 32
Andrey Morozov Avatar answered Oct 03 '22 00:10

Andrey Morozov