0

我想为所有第一个孩子设置顶部边框,以便一个孩子的数据在一行中显示。但我无法为这些行设置 id。我尝试了以下代码,但没有帮助。

final PseudoClass firstRowClass = PseudoClass.getPseudoClass("first-child");

devWorkTabBenchtable.setRowFactory(new Callback<TreeTableView<DevWorkTabBench>, TreeTableRow<DevWorkTabBench>>() {

    @Override
    public TreeTableRow<DevWorkTabBench> call(TreeTableView<DevWorkTabBench> param) {
        TreeTableRow<DevWorkTabBench> row = new TreeTableRow<>();
        row.treeItemProperty().addListener(new ChangeListener<TreeItem<DevWorkTabBench>>() {
            int i = 0;

            @Override
            public void changed(ObservableValue<? extends TreeItem<DevWorkTabBench>> observable, TreeItem<DevWorkTabBench> oldValue, TreeItem<DevWorkTabBench> newValue) {
                if (i < param.getRoot().getChildren().size()) {
                    row.pseudoClassStateChanged(firstRowClass, newValue == param.getRoot().getChildren().get(i));
                }
                i++;
            }
        });
        return row;
    }
});

我应该使用什么?请指导我。

4

1 回答 1

0

尝试这个

treeTableView.setRowFactory( new Callback<TreeTableView<DevWorkTabBench>, TreeTableRow<DevWorkTabBench>>()
{
    @Override
    public TreeTableRow<DevWorkTabBench> call( TreeTableView<DevWorkTabBench> param )
    {
        TreeTableRow<DevWorkTabBench> row = new TreeTableRow<>();
        row.treeItemProperty().addListener( new ChangeListener<TreeItem<DevWorkTabBench>>()
        {
            @Override
            public void changed( ObservableValue<? extends TreeItem<DevWorkTabBench>> observable, TreeItem<DevWorkTabBench> oldValue, TreeItem<DevWorkTabBench> newValue )
            {
                row.pseudoClassStateChanged( firstRowClass, param.getRoot().getChildren().contains( newValue ) );
            }
        } );
        return row;
    }
} );

如何为不同级别应用多个伪类?

您可以获取valuePropertyTreeItem决定应用哪个 css 类:

DevWorkTabBench bench = newValue.getValue();

row.pseudoClassStateChanged( thirdLevelClass, bench.getLevel() == 3 );
// or
row.pseudoClassStateChanged( MyCSSUtils.getClassByLevel(bench.getLevel()), true );
于 2015-05-21T11:46:18.653 回答