我想用JavaFX TableView模拟数据库表GUI,它有一个特殊的列来表示行状态。以下是MS Access的示例:
因此,我希望特殊列具有与表头完全相同的颜色。我不想明确地猜测样式,我不想继承已经为标题设置的颜色。
有可能吗?
答案 0 :(得分:0)
默认样式表使用
-fx-background-color: -fx-box-border, -fx-inner-border, -fx-body-color;
-fx-background-insets: 0, 0 1 1 0, 1 2 2 1;
表示标题。所以你可以尝试类似的东西:
.row-header-cell {
-fx-background-color: -fx-box-border, -fx-inner-border, -fx-body-color;
-fx-background-insets: 0, 0 1 1 0, 1 2 2 1;
}
.table-row-cell:selected .row-header-cell {
-fx-body-color: gold ;
}
然后在“行标题”列上使用单元工厂:
TableColumn<...> rowHeaderColumn = ... ;
rowHeaderColumn.setCellFactory(col -> {
TableCell<...> cell = new TableCell<>();
cell.getStyleClass().add("row-header-cell");
return cell ;
});