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

TreeView bug with setGraphic and scrolling

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P4
    • fx2.1
    • fx2.1
    • javafx
    • Windows 7, JavaFX 2.1 b08

    Description

      Hi,

      please consider the following simple test case and the attachments. Start scrolling with the scrollbar or the mouse wheel and see the strange behavior. It is related to the setGraphic method. If I don't use it, it works fine.





      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.TreeCell;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeView;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.Callback;


      public class TestApp3 extends Application {
          public static void main(String[] args) throws Exception {
              launch(args);
          }

          public void start(final Stage stage) throws Exception {

              VBox root = new VBox();


              TreeView<String> treeView = new TreeView<String>(new TreeItem<String>());
              treeView.setShowRoot(false);

              treeView.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {
                  @Override
                  public TreeCell<String> call(TreeView<String> stringTreeView) {
                      TreeCell<String> treeCell = new TreeCell<String>() {
                          @Override
                          protected void updateItem(String item, boolean isEmpty) {
                              super.updateItem(item, isEmpty);

                              if (item != null) {
                                  if (!item.startsWith("Sub")) {
                                      Label label = new Label(item);
                                      setGraphic(label);
                                  } else {
                                      setText(item);
                                  }
                                  getTreeItem().setExpanded(true);
                              }
                          }
                      };

                      return treeCell;
                  }
              });

              for (int i = 0; i < 20; i++) {
                  TreeItem<String> treeItem = new TreeItem<String>();

                  treeItem.setValue("TreeItem " + i);


                  for (int j = 0; j < 5; j++) {
                      TreeItem<String> subTreeItem = new TreeItem<String>();
                      subTreeItem.setValue("SubTreeItem" + i + "." + j);
                      treeItem.getChildren().add(subTreeItem);
                  }


                  treeView.getRoot().getChildren().add(treeItem);
              }


              root.getChildren().add(treeView);

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

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            cschudtjfx Christian Schudt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: