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

TableView Cell Headers go out of Alignment when Columns Removed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8u20
    • 8u20
    • javafx
    • Windows 8.1, 64-bit, Java 8u20 build 11

    Description

      Compile and run the following code:

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.*;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.StackPane;
      import javafx.scene.text.TextAlignment;
      import javafx.stage.Stage;

      public class HeaderBug extends Application {

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

          @Override public void start(Stage primaryStage) {
              StackPane root = new StackPane();
              root.getChildren().add( buildTable() );
              primaryStage.setScene(new Scene(root, 550, 250));
              primaryStage.show();
          }

          private TableView buildTable() {

              // create table with a bunch of rows
              TableView<Integer> table = new TableView<>();
              for ( int i = 1; i <= 50; i++ ) {
                  table.getItems().add(i);
              }

              // ... and a bunch of differently sized columns
              for ( int i = 0; i < 20; i++ ) {
                  final TableColumn<Integer, Integer> column = new TableColumn<>("Column " + i);
                  table.getColumns().add( column );

                  final int columnIndex = i;

                  // when you click on any cell, it's entire column is removed from table
                  column.setCellFactory(c -> new TableCell<Integer, Integer>() {
                          {
                              setTextAlignment( TextAlignment.CENTER );
                              setOnMouseClicked( (MouseEvent e) -> table.getColumns().remove( column ) );
                          }

                          @Override protected void updateItem(Integer item, boolean empty) {
                              super.updateItem(item, empty);

                              if (empty) {
                                  setText("");
                              } else {
                                  setText("column " + columnIndex);
                              }
                          }
                      }
                  );
              }

              return table;
          }
      }


      -----------------------------

      Once the sample app is running, do the following steps:

      1) use the bottom scrollbar to scroll all the way to the right (so you can see column 19)
      2) click on any random cell in any random column (e.g. column 14, 15, 17, etc)
      3) repeat step 2 a few times. stay scrolled all the way to the right.

      Each time you click on any cell in a column, the entire column is removed from the table.

      If you do this a couple times, you should very quickly see that removing the columns in this manner causes the headers of the TableView go out of alignment with the table's columns.

      This only seems to happen when:

      a) you're scrolled all the way to the right, and
      b) the stage has not been resized so big that you can see all the columns

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            cbanackjfx Cory Banack (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: