Say I have a given TableView<Person>
. And I have a column with a LocalDate
type with a set 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("");
}
}
}
};
});
Is there a way I can get access to the entire Person
for that record within the updateItem()
method? I want to use other attributes of Person
to conditionally format the cell...
TableCell可以访问TableView及其在项目列表中的索引,因此您可以执行以下操作:
Person person = getTableView().getItems().get(getIndex());
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.