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

Moving columns when other columns are not visible not working

XMLWordPrintable

      The code below creates a TreeTableView with 10 columns numbered 1 to 10. Columns 3 and 4 are hidden.
      When trying to move column 2 between columns 5 and 6, it is actually moved between 3 and 4 (can be verified in the column selection menu), so it looks like it is not moving.
      When trying to move column 2 between 7 and 8 it gets inserted between 5 and 6.

      So the offset that the column is moved by seems to be calculated without skipping hidden columns.

      Thanks

      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.scene.Scene;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.scene.layout.AnchorPane;
      import javafx.stage.Stage;

      public class A extends Application {

          @Override
          public void start(Stage stage) throws Exception {
              TreeTableView<String> table =getTreeTable();
              AnchorPane pane = new AnchorPane(table);
              Scene s = new Scene(pane);
              stage.setScene(s);
              stage.show();
          }
          private TreeTableView<String> getTreeTable() {
              TreeItem<String> root = new TreeItem<String> ("This is the root") {
                  @Override public boolean isLeaf() { return false; }
              };
              root.setExpanded(true);
              root.getChildren().add(new TreeItem<String> ("a very very very long leaf") {
                  @Override public boolean isLeaf() { return true; }
              });
              TreeTableView<String> table = new TreeTableView<>(root);
              table.setShowRoot(true);
              table.setTableMenuButtonVisible(true);

              for (int i = 1; i <= 10; i++) {
                  TreeTableColumn<String, String> c = new TreeTableColumn<>(String.valueOf(i));
                  int i_final = i;
                  c.setCellValueFactory((item) -> {
                      String s = item.getValue().getValue();
                      return s.length() > i_final ? new SimpleStringProperty(s.substring(i_final, i_final + 1)) : null;
                  });
                  table.getColumns().add(c);
                  if (i == 3 || i == 4) c.setVisible(false);
              }

              AnchorPane.setLeftAnchor(table, 0d);
              AnchorPane.setTopAnchor(table, 0d);
              AnchorPane.setRightAnchor(table, 0d);
              AnchorPane.setBottomAnchor(table, 0d);

              return table;
          }

          public static void main(String[] args) {
              Application.launch(A.class);
          }
      }

            jgiles Jonathan Giles
            ytallecjfx Yann Le Tallec (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: