@Timst's answer is correct, but you have to change the method of the "updateItem" method in the above case, when you cannot set the "TreeItem" graphic and the tree crashes will not work properly (wonβt clear the text in the subsets).
just change the method to:
@Override protected void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (!empty && item != null) { setText(item); setGraphic(getTreeItem().getGraphic()); }else{ setText(null); setGraphic(null); } }
source share