gpt4 book ai didi

java - 如何使用 JavaFX 从选定 TableRow 中的 TableCell 中删除选择

转载 作者:行者123 更新时间:2023-12-01 12:34:47 26 4
gpt4 key购买 nike

我有一个带有一些列的 TableView。一列包含自定义 TableCell 节点。我想在选择行时从该列单元格中删除选择突出显示。

这是显示我想要的示例图像:

enter image description here

我该怎么做?

最佳答案

使用自定义单元工厂向单元添加样式类:

    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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com