假设我有一个给定的 TableView<Person>
。我有一列 LocalDate
键入一组cellFactory()
。
birthdayColumn.setCellFactory(column -> {
return new TableCell<Person, LocalDate>() {
@Override
protected void updateItem(LocalDate item, boolean empty) {
super.updateItem(item, empty);
//Person person = ... I want to get entire Person, not just LocalDate item
if (item == null || empty) {
setText(null);
setStyle("");
} else {
// Format date.
setText(myDateFormatter.format(item));
// Style all dates in March with a different color.
if (item.getMonth() == Month.MARCH) {
setTextFill(Color.CHOCOLATE);
setStyle("-fx-background-color: yellow");
} else {
setTextFill(Color.BLACK);
setStyle("");
}
}
}
};
});
有什么方法可以访问整个 Person
对于updateItem()
内的记录方法?我想使用 Person
的其他属性有条件地格式化单元格...
最佳答案
TableCell 可以访问 TableView 及其在项目列表中的索引,因此您可以执行以下操作:
Person person = getTableView().getItems().get(getIndex());
关于JavaFX-获取 cellFactory() 的整个行项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35661981/