TreeView's preferred size jumps around

XMLWordPrintable

      package main;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeView;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class Main extends Application {

          TreeView tree_view;
          int itemIndex = 0;

          @Override
          public void start(Stage stage) {
              HBox content = new HBox();
              tree_view = new TreeView();
              tree_view.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              TreeItem<String> tree_model = new TreeItem<String>("Root");
              for (int i = 0; i < 10; i++) {
                  TreeItem node = new TreeItem("Data item " + i);
                  tree_model.getChildren().add(node);
                  for (int j = 0; j < 100; j++) {
                      node.getChildren().add(new TreeItem("Sub node " + j));
                  }
              }
              tree_view.setRoot(tree_model);
              tree_view.setShowRoot(true);
              //tree_view.setCellFactory(new TextFieldTreeCellFactory<String>());

              content.getChildren().add(tree_view);
              stage.setScene(new Scene(content));
              stage.show();
          }
          public static void main(String[] args) {
              launch(Main.class, args);
          }
      }


      You can use either HBox or VBox. ( I didn't check other containers )

      Try to expand or collapse main window (scene) and at the same time expande or collapse items of the tree.
      Example 1, if you expand tree a few times, collapse it to root node, and try to change size of scene = size of treeView control will jump to decrease.
      Example 2, after first expanding of root node, size of tree view control is not proper.

            Assignee:
            Jonathan Giles
            Reporter:
            Alexander Kirov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: