Converting Integer to ObservableValue in javafx

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

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

相关标签:
4条回答
  • 2021-01-11 10:05

    Another way.

    new SimpleIntegerProperty(integer_value).asObject()
    
    0 讨论(0)
  • 2021-01-11 10:17

    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();
    
    0 讨论(0)
  • 2021-01-11 10:20

    if you use tableview do this : just change Integer to Number

    @FXML
    private TableColumn<Sockets,Number> key;
    ...
    key.setCellValueFactory(cellData -> cellData.getValue().socketIdProperty());
    
    0 讨论(0)
  • 2021-01-11 10:32

    IntegerProperty implements ObservableValue<Number> not ObservableValue<Integer>. So you should do:

    // Here Person is a class and age is a variable of type IntegerProperty
    ObservableValue<Number> ob = Person.age;
    
    0 讨论(0)
提交回复
热议问题