Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8187309

TreeCell: must not interfere with custom commitHandler


    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:



      TreeViewCell sets the treeItem's value in its commitEdit method: doing so interferes with a custom handler (which may or may not accept the new value). It's clearly breaking the specified behaviour of the edit mechanism and is a singularity in all virtual controls.

      To reproduce, run the example, edit an item such that oldValue.length > newValue.length and commit:

      - expected: oldValue shown in tree
      - actual: newValue shown in tree

      Setting priority to p2, because the behaviour may corrupt data integrity and there's no clean way to get around.

      The example:

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeView;
      import javafx.scene.control.cell.TextFieldTreeCell;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

       * TreeViewCell: must not interfere with custom commit handler
      public class TreeViewEditCommitInterfere extends Application {

          public void start(Stage stage) throws Exception {
              TreeItem<String> rootItem = new TreeItem<>("root");
              TreeItem<String> child = new TreeItem<>("child");
              TreeView<String> treeView = new TreeView<>(rootItem);
              // custom commit handler: replace value on some condition only
              treeView.setOnEditCommit(t -> {
                  String ov = t.getOldValue();
                  String nv = t.getNewValue();
                  if (nv.length() > ov.length()) {

              Button check = new Button("Print child value");
              check.setOnAction(e -> System.out.println(child.getValue()));
              BorderPane pane = new BorderPane(treeView);
              Scene scene = new Scene(pane, 400, 300);

          public static void main(String[] args) {


          Issue Links



              • Assignee:
                aghaisas Ajit Ghaisas
                fastegal Jeanette Winzenburg
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: