繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM