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

[TreeView] Unexpected scrolling behaviour of TreeView

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u5
    • javafx
    • None
    • OSX 10.9.3, Retina MBP

      When I expand nodes, the node that I expand, sometimes changes its position. This is unusual (I have never seen this in any UI toolkit or application I have used so far) and problematic as far as the user experience is concerned.

      I have attached a runnable test case.

      To reproduce
      - Start it
      - expand the root node
      - expand the node "19"
      - scroll all the way down
      - expand the node "194" it jumps up, which is the behavior I am trying to describe.


      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      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;
      import javafx.util.Callback;

      import java.util.Random;

      public class TreeTest extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception {
              final StackPane stackPane = new StackPane();
              final TreeView<Long> tree = new TreeView<>(new NumberTreeItem(1));
              tree.setCellFactory(new Callback<TreeView<Long>, TreeCell<Long>>() {
                  @Override
                  public TreeCell<Long> call(TreeView<Long> param) {
                      return new TreeCell<Long>() {
                          @Override
                          protected void updateItem(Long item, boolean empty) {
                              super.updateItem(item, empty);
                              if (!empty) {
                                  setText(item != null ? String.valueOf(item) : "");
                              } else{
                                  setText(null);
                              }
                          }
                      };
                  }
              });
              stackPane.getChildren().add(tree);
              final Scene scene = new Scene(stackPane);
              primaryStage.setScene(scene);
              primaryStage.setTitle(getClass().getSimpleName());
              primaryStage.show();
          }

          private static class NumberTreeItem extends TreeItem<Long>{

              private boolean loaded = false;

              private NumberTreeItem(long value) {
                  super(value);
              }

              @Override
              public boolean isLeaf() {
                  return false;
              }

              @Override
              public ObservableList<TreeItem<Long>> getChildren() {
                  if(!loaded){
                      final ObservableList<TreeItem<Long>> children = super.getChildren();
                      for (int i = 0; i < 10; i++) {
                          children.add(new NumberTreeItem(10 * getValue() + i));
                      }
                      loaded = true;
                  }
                  return super.getChildren();
              }
          }

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

            Unassigned Unassigned
            rkruegerjfx Robert Krueger (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Imported: