Converting Integer to ObservableValue in javafx

后端 未结 4 1705
后悔当初
后悔当初 2021-01-11 09:51

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

4条回答
  •  鱼传尺愫
    2021-01-11 10:17

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

    ObservableValue obsInt = new ReadOnlyObjectWrapper<>(intValue);
    

    Update

    Starting JavaFX 8, you can also do the following :

    ObservableValue obsInt = new SimpleIntegerProperty(intValue).asObject();
    

提交回复
热议问题