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?
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. 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.
You are getting a Property
, and more precisely an 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.
To get the value, just call get()
.
You can call getValue
method of extended class ObjectExpression
:
getCellObservableValue(0).getValue()
https://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/ObjectExpression.html#getValue--
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.