更改 CSS JavaFX 中复选框树项的样式

Change CSS styling of a checkbox tree item in JavaFX

我正在使用 JavaFX 8,并且有一个 treeView 填充了复选框树项目,如此 picture 所示。我想申请 CSS 这样我就可以:

  1. 更改复选框的背景颜色
  2. 更改复选框的边框颜色
  3. 更改复选框内选择图标的颜色

我到处搜索,但一直无法弄清楚如何执行此操作,并尝试了以下命令的多种变体,但无法使其正常工作。

.tree-view .check-box-tree-cell .check-box {
    -fx-background-color: black;
    -fx-border-color: orange
}

.tree-view .check-box {
    -fx-background-color: black;
    -fx-border-color: orange
}

.check-box-tree-cell {
    -fx-background-color: black;
    -fx-border-color: orange
}

.tree-cell .check-box {
    -fx-background-color: black;
    -fx-border-color: orange;
}

我该如何解决这个问题?

试试这个:

.tree-view .check-box .box {
    -fx-background-color: lightskyblue;
    -fx-border-color: dodgerblue;
}

.tree-view .check-box:selected .box .mark,
.tree-view .check-box:indeterminate .box .mark {
    -fx-background-color: midnightblue;
}

如果您使用 CheckBoxTreeCell:

,这也有效
.check-box-tree-cell > .check-box > .box {
    -fx-background-color: lightskyblue;
    -fx-border-color: dodgerblue;
}

.check-box-tree-cell > .check-box:selected > .box > .mark,
.check-box-tree-cell > .check-box:indeterminate > .box > .mark {
    -fx-background-color: midnightblue;
}