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

TableHeaders behave badly when horizontal scrollbar is visible

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 8
    • Component/s: javafx
    • Environment:

      Windows 8, Lombard build 109

      Description

      Compile and run the following code. It creates a simple table with 6 columns and 50 rows. The rows are filled with integers so that each column can be sorted, but otherwise the contents of the table are not important.

      *********************************
      import javafx.application.Application;
      import javafx.beans.property.ReadOnlyIntegerWrapper;
      import javafx.beans.value.ObservableIntegerValue;
      import javafx.scene.Scene;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

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

         @Override public void start(Stage primaryStage) {
             primaryStage.setTitle("Table Header Bugs Demo");
             StackPane root = new StackPane();
             root.getChildren().add( buildTable() );
             primaryStage.setScene(new Scene(root, 250, 250));
             primaryStage.show();
         }

         private TableView buildTable() {

            // create a table with 6 identical columns
            final TableView<Integer> table = new TableView<>();
            for ( int x = 1; x <= 6; x++ ) {
               TableColumn<Integer, Integer> col = new TableColumn<>("Column "+x);
               setupValueFactory( col );
               col.setPrefWidth( 100 );
               table.getColumns().add( col );
            }

            // add integers from 1 to 5 as items in the table
            for ( int i = 1; i <= 5; i++ ) {
               table.getItems().add(i);
            }

            return table;
         }

         // sets up a simple value factory for displaying integers in this table cell
         private void setupValueFactory(TableColumn col) {
            col.setCellValueFactory(
               new javafx.util.Callback<TableColumn.CellDataFeatures<Integer, Integer>,
                     ObservableIntegerValue>() {
                  public ObservableIntegerValue call(TableColumn.CellDataFeatures<Integer, Integer> p) {
                     return new ReadOnlyIntegerWrapper(p.getValue());
                  }
               });
         }
      }

      ***********************************************************

      Note how the default size of the window is set so that the table's horizontal scrollbar is visible (i.e. so that you can't see all of the columns without scrolling.) There are a couple of problems with the table headers in this situation.

      1) If you try to reorder the columns by dragging, the alignment of the column headers often gets temporarily out of sync. That is, the header cells and the column cells don't line up anymore--in fact the headers may not even appear over the correct columns. This glitch is easiest to see if you scroll all the way over to the right and then grab Column 6 and swap its position with Column 5. If that doesn't work, just keep reordering various columns, you'll quickly see the problem.

      2) Each time you click on the header for a column (to sort it), the table's view scrolls all the way back to the left. This is very jarring, since any user who changes the sorting for a column will likely also want to then see the newly sorted contents of that column. The way things are now, if the user wants to sort column 6, she has to scroll over to column 6, sort it, and then scroll over to it again in order to see the sorted contents. (This behaviour may also be related to http://javafx-jira.kenai.com/browse/RT-31085 .)

      3) It's very difficult to reorder columns across "long distances" when the horizontal scrollbar is present. To see what I mean, just try and see how hard it is to swap the positions of columns 1 and 6 without resizing the table. Some of the pain here is caused by problem #1 above, but it's equally problematic that the table doesn't scroll automatically while I drag the column. For example, if I grab column 1 and start dragging it to the right, once I get to the edge of the table, the table should start slowly scrolling to the right, one column at a time. I think this behaviour is fairly common in GUI libraries that implement tables with re-orderable columns. It's necessary because otherwise you have to drag a bit, scroll a bit, drag a bit, scroll a bit, etc, until you finally get the column where it needs to go!

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                msladecek Martin Sládeček
                Reporter:
                cbanackjfx Cory Banack (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved:
                  Imported: