JavaFX样式化TableColumn单元格 [英] JavaFX styling TableColumn cells
问题描述
我正在Gluon Scene Builder中构建一个TableView.我希望每列中的单元格具有不同的背景色.我可以仅通过FXML文件和CSS来做到这一点吗?
I am building a TableView in Gluon Scene Builder. I want to have a different background colour for cells in each column. Can I do this just through the FXML file and CSS?
使用CSS样式类.column-1,我可以做到:
With a CSS style class .column-1 I can do:
.column-1 {-fx-background-color: white;}
除了还可以设置列标题的样式!似乎没有办法只指定列单元格.
Except that also styles the column header! There doesn't seem to be a way to specify column cells only.
我已经看到了人们通过Java代码对其进行管理的示例-但这不会破坏JavaFX具有这种CSS/FXML能力的观点吗?
I have seen examples where people have managed it through java code - but doesn't this defeat the point of JavaFX having this CSS/FXML ability?
推荐答案
您可以使用多个类选择器来选择单元格:
You could use multiple class selectors to select the cells:
.column-1.table-cell {
-fx-background-color: white;
}
<TableColumn styleClass="column-1">
这篇关于JavaFX样式化TableColumn单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!