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

2.1k views Asked by At

I need to apply CSS to change collapse/expand icons for a particular treeview in my JavaFX application. FX:ID for it is treeView. However I have many other treeviews in my application and I don't want those icons to be changed.

Change expand and collapse image TreeView JavaFX 2.2

Above link provides a solution to apply CSS but that would change icons in all the treeViews. Is there any way I can apply CSS to particular treeView?

1

There are 1 answers

6
ItachiUchiha On BEST ANSWER

You can assign a separate class to your TreeView and change its icon.

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

and change the icons only for this 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;
}