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

Scroll bar doesn't appear when increasing tree table column min width

    XMLWordPrintable

Details

    Description

      To reproduce push the button 'Increase min width'
      You will see that the title will get correct offset but there will be
      no scroll bar until you collapse the root

      import com.sun.javafx.runtime.VersionInfo;
      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.value.ObservableValue;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      import javafx.util.Callback;

      public class TreeTableSample1 extends Application {

          TreeTableView<Person> treeTableView;
          TreeTableColumn<Person, String> firstNameCol;

          @Override
          public void start(Stage primaryStage) {

              initTreeTableView();

              HBox root = new HBox(10.0);
              root.getChildren().add(treeTableView);

              Button action = new Button("Increase min width");
              action.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent actionEvent) {
                      System.out.println("Setting min width to 500");
                      firstNameCol.setMinWidth(500);
                  }
              });

              VBox vb = new VBox(10.0);
              vb.getChildren().add(action);

              root.getChildren().add(vb);

              Scene scene = new Scene(root, 400, 300);

              primaryStage.setTitle(VersionInfo.getRuntimeVersion());
              primaryStage.setScene(scene);
              primaryStage.show();
          }

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

          private void initTreeTableView() {
              treeTableView = new TreeTableView<Person>();
              treeTableView.setMinSize(200, 150);
              treeTableView.setPrefSize(200, 200);
              treeTableView.setMaxSize(200, 250);
              treeTableView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);

              TreeItem<Person> root = new TreeItem<Person>(new Person("Anna"));
              root.setExpanded(true);
              treeTableView.setRoot(root);
              treeTableView.showRootProperty().set(true);

              firstNameCol = new TreeTableColumn<Person, String>("First name");
              firstNameCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, String>, ObservableValue<String>>() {
                  @Override
                  public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Person, String> p) {
                      return p.getValue().getValue().firstName;
                  }
              });
              firstNameCol.setMinWidth(80d);

              treeTableView.getColumns().addAll(firstNameCol);

              Person p = new Person("Bob");
              treeTableView.getRoot().getChildren().add(new TreeItem<Person>(p));

              p = new Person("Cindy");
              treeTableView.getRoot().getChildren().add(new TreeItem<Person>(p));

              p = new Person("Zack");
              treeTableView.getRoot().getChildren().add(new TreeItem<Person>(p));
          }

          class Person implements Comparable{

              public final SimpleStringProperty firstName;

              public Person(String name) {
                  this.firstName = new SimpleStringProperty(name);
              }

              public String toString() {
                  return firstName.get();
              }

              @Override
              public int compareTo(Object o) {
                  return this.firstName.get().compareTo(((Person) o).firstName.get());
              }
          }
      }

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            dzinkevi Dmitry Zinkevich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: