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

ChangeListeners attached to TreeItem#expandedProperty() are not notified when child nodes are expanded/collapsed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • fx2.0
    • None
    • javafx

      According to Jonathan Giles in https://forums.oracle.com/forums/message.jspa?messageID=9929460, tree item events are supposed to bubble up the tree item parent chain. The following code should then print "EXPANDED: .. " when expanding the Item 1 node, which is a child of the root node, but the listener is only notified about changes on the root node:

      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.scene.Scene;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeView;
      import javafx.stage.Stage;

      public class TreeViewTest extends Application {

          public void start(Stage stage) throws Exception {
              TreeItem<String> root = new TreeItem<String>("Root Node");
              TreeItem<String> item1 = new TreeItem<String>("Item 1");
              root.getChildren().add(item1);
              item1.getChildren().add(new TreeItem<String>("Child of Item 1"));

              TreeView<String> treeView = new TreeView<String>(root);

              root.expandedProperty().addListener(new ChangeListener<Boolean>() {
                  public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean aBoolean1) {
                      System.out.println("EXPANDED: " + observableValue.getValue());
                  }
              });

              Scene scene = new Scene(treeView);
              stage.setScene(scene);
              stage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }

            jgiles Jonathan Giles
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: