如何更改 javafx 中特定树视图的折叠和展开图标?

How to change collapse and expand icon for a particular treeview in javafx?

我需要应用 CSS 来更改我的 JavaFX 应用程序中特定树视图的 collapse/expand 图标。 FX:ID 因为它是 treeView。但是我的应用程序中还有许多其他树视图,我不想更改这些图标。

Change expand and collapse image TreeView JavaFX 2.2

以上 link 提供了应用 CSS 的解决方案,但这会更改所有 treeView 中的图标。有什么方法可以将 CSS 应用于特定的 treeView?

您可以为您的 TreeView 分配一个单独的 class 并更改其图标。

treeView.getStyleClass().add("my-tree-view");

并仅为该 treeView 更改图标

.my-tree-view > .virtual-flow> .clipped-container > .sheet > .tree-cell .tree-disclosure-node .arrow {
    -fx-background-color: red;
}
.my-tree-view > .virtual-flow> .clipped-container > .sheet > .tree-cell:expanded .tree-disclosure-node .arrow {
    -fx-background-color: blue;
}