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

Table view header cells not aligned with content cells after horizontal scrolling

    XMLWordPrintable

Details

    • x86_64
    • windows_7

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_72"
      Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The problem consist in having a lack of visual correspondence between header cells and content cells in table views where data appears after the user altered the viewport by scrolling horizontally completely to the right. The offset between header cells and content cells seems to be equal to the width of the vertical scroll bar.

      This issue is visible when data appears, disappears and then appears again, if the user managed to scroll horizontally.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Define a table view with enough items so that both vertical and horizontal scroll bars are visible.
      2. Scroll horizontally to the right, completely, until the thumb touches the increment button.
      3. Have data disappear.
      4. Have data appear again.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Header cells and content cells are perfectly aligned.
      ACTUAL -
      A visual offset appears between header cells and content cells, apparently equal to the width of the vertical scroll bar. (Also, the horizontal scroll bar is no longer at the right side of the view, but this is not necessarily a problem.)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.beans.property.SimpleObjectProperty;
      import javafx.beans.value.ObservableValue;
      import javafx.geometry.Insets;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      import java.util.ArrayList;
      import java.util.List;
      import java.util.Random;

      public class TableViewScrollingIssue extends Application {
          private static final int COLUMN_COUNT = 10;
          private static final int ROW_COUNT = 20;

          @Override
          public void start(final Stage primaryStage) throws Exception {
              final List<Item> items = new ArrayList<>(ROW_COUNT);
              for (int i = 0; i < ROW_COUNT; i++) {
                  items.add(new Item());
              }

              final List<TableColumn<Item, ?>> columns = new ArrayList<>(COLUMN_COUNT);
              for (int i = 0; i < COLUMN_COUNT; i++) {
                  final int index = i;
                  final TableColumn<Item, Integer> column = new TableColumn<>("Column " + i);
                  column.setCellValueFactory(param -> param.getValue().getProperty(index));
                  columns.add(column);
              }

              final TableView<Item> tableView = new TableView<>();
              tableView.getColumns().setAll(columns);

              final Button generateDataButton = new Button("Set");
              generateDataButton.setOnAction(e -> tableView.getItems().setAll(items));

              final Button clearDataButton = new Button("Clear");
              clearDataButton.setOnAction(e -> tableView.getItems().clear());

              final HBox buttonBox = new HBox(5, generateDataButton, clearDataButton);
              buttonBox.setPadding(new Insets(10));
              buttonBox.setAlignment(Pos.CENTER);

              final BorderPane borderPane = new BorderPane();
              borderPane.setCenter(tableView);
              borderPane.setBottom(buttonBox);

              primaryStage.setTitle("Table View Scrolling Issue");
              primaryStage.setScene(new Scene(borderPane, 600, 400));
              primaryStage.show();
          }

          private static class Item {
              private final List<ObservableValue<Integer>> properties = new ArrayList<>();

              Item() {
                  final Random random = new Random();
                  for (int i = 0; i < COLUMN_COUNT; i++) {
                      properties.add(new SimpleObjectProperty<>(random.nextInt(1000)));
                  }
              }

              ObservableValue<Integer> getProperty(final int index) {
                  return properties.get(index);
              }
          }

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

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      A possible solution is to react to the visibility change of the placeholder node; when it disappears, request scrolling to the first column. This triggers the realignment of header and content cells.

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: