我有一个带有一些列的 TableView。一列包含自定义 TableCell 节点。我想在选择行时从该列单元格中删除选择突出显示。
这是显示我想要的示例图像:
我该怎么做?
最佳答案
使用自定义单元工厂向单元添加样式类:
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 ;
});
然后在外部样式表中,将所选行中的 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 ;
}
关于java - 如何使用 JavaFX 从选定 TableRow 中的 TableCell 中删除选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25686624/