gpt4 book ai didi

JavaFX-获取 cellFactory() 的整个行项目?

转载 作者:行者123 更新时间:2023-11-30 03:02:16 25 4
gpt4 key购买 nike

假设我有一个给定的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com