[英]How to remove selection from a TableCell in a selected TableRow with JavaFX
I have a TableView with some columns. 我有一些列的TableView。 One column contains custom TableCell nodes.
一列包含自定义TableCell节点。 I want to remove the selection highlight from that column cell when the row is selected.
当要选择行时,我想从该列单元格中删除选择突出显示。
Here is the sample image which shows what I want: 这是显示我想要的示例图像:
How can I do this? 我怎样才能做到这一点?
Use a custom cell factory to add a style class to the cell: 使用自定义单元工厂将样式类添加到单元:
firstNameCol.setCellFactory(col -> {
TableCell<Person, String> cell = new TableCell<Person, String>() {
@Override
public void updateItem(String name, boolean empty) {
super.updateItem(name, empty);
if (empty) {
setText("");
} else {
setText(name);
}
}
};
cell.getStyleClass().add("no-select-cell");
return cell ;
});
And then in an external stylesheet, revert the style for no-select-cell
in selected rows to the defaults: 然后在外部样式表中,将选定行中的
no-select-cell
样式还原为默认值:
.table-row-cell:selected .no-select-cell {
-fx-background: -fx-control-inner-background;
-fx-background-color: -fx-background;
-fx-text-fill: -fx-text-background-color;
}
.table-row-cell:odd:selected .no-select-cell {
-fx-background: -fx-control-inner-background-alt ;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.