我想为所有第一个孩子设置顶部边框,以便一个孩子的数据在一行中查找。 但是我无法为这些行设置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;
}
});
我应该使用什么?请指导我。
答案 0 :(得分: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;
}
} );
如何为不同级别应用多个伪类?
您可以获取TreeItem
的{{3}}并决定要应用哪个css类:
DevWorkTabBench bench = newValue.getValue();
row.pseudoClassStateChanged( thirdLevelClass, bench.getLevel() == 3 );
// or
row.pseudoClassStateChanged( MyCSSUtils.getClassByLevel(bench.getLevel()), true );