[英]How can I get the contents of a JavaFX TableColumn?
If I have a TableView in JavaFX with some TableColumn's is there a way I can get the data in that column's cells? 如果我在JavaFX中有一个带有某些TableColumn的TableView,是否有一种方法可以在该列的单元格中获取数据?
TableColumn concentrationCol = new TableColumn("Initial Concentration");
concentrationCol.setMinWidth(150);
concentrationCol.setCellValueFactory(
new PropertyValueFactory<SpeciesDoubleWrapper, String>("d"));
concentrationCol.setCellFactory(TextFieldTableCell.forTableColumn());
concentrationCol.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<SpeciesDoubleWrapper, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<SpeciesDoubleWrapper, String> t) {
((SpeciesDoubleWrapper) t.getTableView().getItems().get(
t.getTablePosition().getRow())
).setD(t.getNewValue());
}
}
);
This is the code I use to create my TableColumn. 这是我用来创建TableColumn的代码。 I know there is a function
getCellObservableValue(int i)
which returns the contents of the ith cell, but when I use it I get ObjectProperty [value: 0.0]
returned instead of 0.0
, which is the value of the cell. 我知道有一个函数
getCellObservableValue(int i)
返回第i个单元格的内容,但是当我使用它时,我得到了ObjectProperty [value: 0.0]
而不是0.0
,它是单元格的值。
You are getting a Property
, and more precisely an ObjectProperty
. 您将获得一个
Property
,更确切地说是一个ObjectProperty
。
These classes are used for the concept of data binding . 这些类用于数据绑定的概念。 To make it short, data binding allows JavaFX to keep track of the values if they change and automatically update the view accordingly.
简而言之,数据绑定允许JavaFX跟踪值的更改,并相应地自动更新视图。
You can call getValue
method of extended class ObjectExpression
: 您可以调用扩展类
ObjectExpression
getValue
方法:
getCellObservableValue(0).getValue()
https://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/ObjectExpression.html#getValue-- https://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/ObjectExpression.html#getValue--
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.