[英]JavaFX- Getting Entire Row Item for cellFactory()?
Say I have a given TableView<Person>
. 说我有一个给定的TableView<Person>
。 And I have a column with a LocalDate
type with a set cellFactory()
. 而且我有一列具有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("");
}
}
}
};
});
Is there a way I can get access to the entire Person
for that record within the updateItem()
method? 有没有办法可以在updateItem()
方法中访问该记录的整个Person
? I want to use other attributes of Person
to conditionally format the cell... 我想使用Person
其他属性来有条件地格式化单元格...
TableCell可以访问TableView及其在项目列表中的索引,因此您可以执行以下操作:
Person person = getTableView().getItems().get(getIndex());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.