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

TableView: incorrect scrollTo parent of nested columns



      To reproduce, run the example below und make sure that the parent of nested columns is not/only partly visible

      - click button to scroll to parent of nested columns
      - expected: parent column scrolled to leading edge of table
      - actual: scrolled such that last column aligned with trailing edge, parent scrolled out to left

      Culprit seems to be TableViewSkinBase.scrollHorizontally(targetColumn), in particular its code to calc the horizontal location of the target:

              // work out where this column header is, and it's width (start -> end)
              double start = 0;
              for (TC c : getVisibleLeafColumns()) {
                  if (c.equals(col)) break;
                  start += c.getWidth();

      if col is a parentColumn, the break condition is always false, thus scrolling through to the end.

      The example:

          public class TableViewNestedScrollHorizontalBug extends Application {
              private Parent getContent() {
                  TableView<Locale> table = new TableView<>(FXCollections.observableArrayList(
                  TableColumn<Locale, String> countryCode = new TableColumn<>("CountryCode");
                  countryCode.setCellValueFactory(new PropertyValueFactory<>("country"));
                  TableColumn<Locale, String> language = new TableColumn<>("Language");
                  language.setCellValueFactory(new PropertyValueFactory<>("language"));
                  TableColumn<Locale, String> variant = new TableColumn<>("Variant");
                  variant.setCellValueFactory(new PropertyValueFactory<>("variant"));
                  TableColumn<Locale, String> display = new TableColumn<>("DisplayName");
                  display.setCellValueFactory(new PropertyValueFactory<>("displayLanguage"));
                  TableColumn<Locale, String> nested = new TableColumn<>("Nested");
                  nested.getColumns().addAll(countryCode, language);
                  table.getColumns().addAll(display, nested, variant, new TableColumn<>("Dummy"));
                  Button scrollTo = new Button("ScrollTo Nested");
                  scrollTo.setOnAction(e -> table.scrollToColumn(nested));
                  BorderPane pane = new BorderPane(table);
                  return pane;
              public void start(Stage primaryStage) throws Exception {
                  primaryStage.setScene(new Scene(getContent(), 200, 400));
              public static void main(String[] args) {
              private static final Logger LOG = Logger




            • Assignee:
              fastegal Jeanette Winzenburg
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: