从JavaFX TreeTable CellFactory回调中获取变量

时间:2014-10-20 17:17:39

标签: java javafx javafx-8 treetableview

我正在使用包含BillingTableRow类型项的JavaFX TreeTableView。我希望根据BillingTableRow中的方法getType()给出的值来设置列的样式,但我似乎无法从我正在尝试设置的回调中访问它。这是我的代码:

Callback<TreeTableColumn<BillingTableRow, Double>, TreeTableCell<BillingTableRow, Double>> eveningCallback = new Callback<TreeTableColumn<BillingTableRow, Double>, TreeTableCell<BillingTableRow, Double>>() {
        @Override
        public TreeTableCell<BillingTableRow, Double> call(TreeTableColumn<BillingTableRow, Double> p) {
            return new EditableTreeTableDoubleCell() {
                @Override
                public void updateItem(Double item, boolean empty) {
                    super.updateItem(item, empty);

                    BillingTableRow row = (...)// Get attached BillingTableRow for current tree table row.
                    if (row.getType() == 0) {
                        setText(null);
                    }

                }
            };
        }
    };
    eveningColumn.setCellFactory(eveningCallback);

为了让它起作用,我应该用什么替换(...)?

1 个答案:

答案 0 :(得分:2)

使用

BillingTableRow row = getTreeTableRow().getItem();

TableCellTreeTableCell都定义了tableRow属性,该属性为单元格显示当前单元格所属的整行。对于TreeTableCell<S,T>getTreeTableRow()将返回TreeTableRow<S>,它是Cell<S>的子类。这意味着它有一个getItem()方法,其返回类型为S,即表示整行数据的项。