[英]JavaFX-8 set color for selected TableRow
I have code like this for tablecells in my .css file: 我的.css文件中的表格单元格具有如下代码:
.table-cell-warn
{
-fx-background-color: aliceblue;
}
.table-cell-error
{
-fx-background-color: yellow;
}
I have added those css classes to specific TableCells via. 我已经通过那些css类添加到特定的TableCells中。
o.getStyleClass.add("table-cell-warn")
or o.getStyleClass.add("table-cell-error")
o.getStyleClass.add("table-cell-warn")
或o.getStyleClass.add("table-cell-error")
But when I select a colored TableRow now, it does not use the colors specified for selected TableRows (by default a light blue). 但是当我现在选择彩色的TableRow时,它不使用为选定的TableRows指定的颜色(默认为浅蓝色)。 I tried adding code like this:
我尝试添加如下代码:
.table-cell-warn:selected
{
-fx-background-color: #0096C9;
-fx-accent: #0096C9;
-fx-focus-color: #039ED3;
}
.table-cell-error:selected
{
-fx-background-color: #0096C9;
-fx-accent: #0096C9;
-fx-focus-color: #039ED3;
}
to the .css file, but it changed nothing. 到.css文件,但没有任何改变。 Do I have to change something in my java code, too?
我是否也需要更改Java代码中的某些内容? Or am I on the wrong path.
还是我走错了路。
The TableView
is in "row selection mode", which is why the :selected
pseudoclass is added to the TableRow
containing the TableCell
. TableView
处于“行选择模式”,这就是为什么:selected
伪类被添加到包含TableCell
的TableRow
中的原因。 The following css should work: 以下CSS应该可以工作:
/* for row selection mode */
.table-row-cell:selected .table-cell-warn,
.table-row-cell:selected .table-cell-error,
/* for cell selection mode */
.table-cell-warn:selected,
.table-cell-error:selected
{
-fx-background-color: #0096C9;
-fx-accent: #0096C9;
-fx-focus-color: #039ED3;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.