You can override updateItem method in a TreeCell object . This is a single class app . So, you can test it . Be careful , this aproach would be work with leaf nodes only , because disabled parent nodes can't expand or collapse .
package com.app;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage stage) {
TreeView<String> treeView = new TreeView<>();
treeView.setRoot(new TreeItem<>("People"));
treeView.getRoot().getChildren().addAll(
new TreeItem<>("Fernanado"),
new TreeItem<>("MarĂa"),
new TreeItem<>("Flor"),
new TreeItem<>("Pablo"),
new TreeItem<>("Francisca"));
treeView.setCellFactory(p -> new TreeCell<String>() {
@Override
public void updateItem(String string, boolean empty) {
super.updateItem(string, empty);
if (empty) {
setText("");
setGraphic(null);
} else {
setText(string);
setGraphic(getTreeItem().getGraphic());
// this will disable a TreeItem if String has "F" character
setDisable(string.contains("F"));
}
}
});
Scene scene = new Scene(new StackPane(treeView), 640, 480);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}