将整数转换为可观察值<;整数>;在javafx中
如何在JavaFX2.0及更高版本中将将整数转换为可观察值<;整数>;在javafx中,javafx,javafx-2,Javafx,Javafx 2,如何在JavaFX2.0及更高版本中将Integer转换为observeValue?我们使用ReadOnlyObjectWrapper(*Integer value*)并将值存储在observeValue引用中 ObservableValue<Integer> obsInt = new ReadOnlyObjectWrapper<>(intValue); observeValue obsInt=新的只读对象包装器(intValue); 更新 启动JavaFX8,还可
Integer
转换为observeValue
?我们使用ReadOnlyObjectWrapper(*Integer value*)编码>并将值存储在observeValue
引用中
ObservableValue<Integer> obsInt = new ReadOnlyObjectWrapper<>(intValue);
observeValue obsInt=新的只读对象包装器(intValue);
更新
启动JavaFX8,还可以执行以下操作:
ObservableValue<Integer> obsInt = new SimpleIntegerProperty(intValue).asObject();
observeValue obsit=新的SimpleIntegerProperty(intValue).asObject();
另一种方法
new SimpleIntegerProperty(integer_value).asObject()
IntegerProperty
实现observeValue
非observeValue
。所以你应该:
// Here Person is a class and age is a variable of type IntegerProperty
ObservableValue<Number> ob = Person.age;
//这里Person是一个类,age是IntegerProperty类型的变量
ObservieValue ob=人的年龄;
如果使用tableview,请执行以下操作:
只需将整数改为数字
@FXML
private TableColumn<Sockets,Number> key;
...
key.setCellValueFactory(cellData -> cellData.getValue().socketIdProperty());
@FXML
私有表列密钥;
...
key.setCellValueFactory(cellData->cellData.getValue().socketIdProperty());
#asObject()
是在JavaFX 8中添加的一个微妙问题,如果您需要整数(对象)而不是原语int
(允许空引用),则必须使用ReadOnlyObject包装器,而不是SimpleIntegerProperty