[英]JavaFX- Getting Entire Row Item for cellFactory()?
說我有一個給定的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("");
}
}
}
};
});
有沒有辦法可以在updateItem()
方法中訪問該記錄的整個Person
? 我想使用Person
其他屬性來有條件地格式化單元格...
TableCell可以訪問TableView及其在項目列表中的索引,因此您可以執行以下操作:
Person person = getTableView().getItems().get(getIndex());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.