我正在使用包含类型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);


为了使其正常工作,我应该用(...)代替什么?

最佳答案

采用

BillingTableRow row = getTreeTableRow().getItem();

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

关于java - 从JavaFX TreeTable CellFactory回调内部获取变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26471270/

10-10 20:03