将String转换为ObservableValue< String> [英] Convert a String to an ObservableValue<String>
本文介绍了将String转换为ObservableValue< String>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个 TableView
。在我的 .fxml
控制器中,我有以下两列:
I would like to create a TableView
. In my .fxml
controller, I have these two columns:
@FXML
private TableColumn<Log, String> planeRegistrationColumn;
@FXML
private TableColumn<Log, String> planeTypeColumn;
日志类的属性为 Plane
是一个Plane实例。但 setCellValueFactory
似乎不喜欢它:
The log class has an attribute Plane
which is a Plane instance. But the setCellValueFactory
doesn't seem to like it:
planeRegistrationColumn.setCellValueFactory(cellData -> cellData.getValue().planeProperty().get().getRegistration());
getRegistration()
返回一个字符串,但是它需要 ObservableValue< String>
。这是一个概念问题吗?如果没有,我该怎么做?
getRegistration()
returns a String, but it needs an ObservableValue<String>
. Is it a conception problem? And if not, how to can I do this?
推荐答案
只需将你得到的字符串包装成某种可观察值:
Just wrap the string you get in some kind of observable value:
planeRegistrationColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().planeProperty().get().getRegistration()));
这篇关于将String转换为ObservableValue< String>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文