There is a tree, each element of which inherits the Viewable interface:
public interface Viewable { enum ViewStyle { NEW("-fx-background-color: b8faa7;"), NEW_PARENT("-fx-background-color: b8ebbb;"), LOCKED("-fx-background-color: adadad; "), HAS_NO_DATA("-fx-background-color: eb8d8d;"); String style; ViewStyle(String style){ this.style = style; } public String getStyle() { return style; } } ViewStyle getViewStyle(); void setViewStyle(ViewStyle style); StringProperty styleProperty(); String getTreeItemTitle(); void setTreeItemTitle(String title); StringProperty titleProperty(); } Each object has its own styleProperty() , the value takes from ViewStyle.getStyle()
In the tree itself, to each TreeCell this property is "bound":
treeView.setCellFactory(new Callback<TreeView<Viewable>, TreeCell<Viewable>>() { @Override public TreeCell<Viewable> call(TreeView<Viewable> param) { return new TreeCell<Viewable>() { @Override protected void updateItem(Viewable item, boolean empty) { textProperty().unbind(); styleProperty().unbind(); if (empty || item == null) { setGraphic(null); textProperty().set(null); styleProperty().set(null); } if (item != null) { styleProperty().bind(item.styleProperty()); textProperty().bind(item.titleProperty()); } super.updateItem(item, empty); } }; } }); The problem is that the tree rows are ugly displayed when selected. Those. the color of the selected cell does not change. Understand that a cell can only be selected by changing the color of the letters, and this is not very convenient. By this, you probably have to attach .css files. It is not clear how to change the style of the cell depending on the current ViewStyle .