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

TableView.scrollTo(TableColumn) doesn't work when called after setVisible(true)



    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:

      Build 92, on Windows 8


      Compile and run the following code. Note that it is identical to the code I just submitted for another bug (https://javafx-jira.kenai.com/browse/RT-31084) except there is an extra line at the end of the EventHandler that calls TableView.scrollTo() to scroll to Column 4.

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

      public class TableScrollToBug extends Application {
         public static void main(String[] args) {
         @Override public void start(Stage primaryStage) {
             primaryStage.setTitle("Table ScrollTo Bug Demo");
             StackPane root = new StackPane();
             root.getChildren().add( buildTable() );
             primaryStage.setScene(new Scene(root, 150, 250));
         private TableView buildTable() {
            // create a table with 4 identical columns, the last three are invisible
            final TableView<Integer> table = new TableView<>();
            final TableColumn<Integer, Integer> column1 = new TableColumn<>("Column 1");
            setupValueFactory( column1 );
            column1.setPrefWidth( 100 );

            final TableColumn<Integer, Integer> column2 = new TableColumn<>("Column 2");
            column2.setPrefWidth( 100 );
            column2.setVisible( false );
            setupValueFactory( column2 );
            final TableColumn<Integer, Integer> column3 = new TableColumn<>("Column 3");
            column3.setPrefWidth( 100 );
            column3.setVisible( false );
            setupValueFactory( column3 );
            final TableColumn<Integer, Integer> column4 = new TableColumn<>("Column 4");
            column4.setPrefWidth( 100 );
            column4.setVisible( false );
            setupValueFactory( column4 );
            table.getColumns().setAll( column1, column2, column3, column4 );
            // add integers from 1 to 50 as items in the table
            for ( int i = 1; i <= 50; i++ ) {
            // when user ctrl-clicks on the table, make the next column visible
            table.setOnMouseClicked( new EventHandler<MouseEvent>() {
               public void handle( MouseEvent e ) {
                  if ( e.isShortcutDown() ) {
                     column2.setVisible( true );
                     column3.setVisible( true );
                     column4.setVisible( true );
                     table.scrollToColumn( column4 );
            return table;
         // sets up a simple value factory for displaying integers in this table cell
         private void setupValueFactory(TableColumn col) {
               new javafx.util.Callback<TableColumn.CellDataFeatures<Integer, Integer>, ObservableIntegerValue>() {
                  public ObservableIntegerValue call(TableColumn.CellDataFeatures<Integer, Integer> p) {
                     return new ReadOnlyIntegerWrapper(p.getValue());


      Just like with bug RT-31084, this code produces a TableView<Integer> with 4 columns that all simply display the Integer item for their row. 3 of the 4 columns start out hidden (visible==false), but when you hold down control and click anywhere on the table, 1) those hidden columns become visible, and 2) we call scrollTo() in an attempt to make column 4 visible to the user.

      To see the bug:

      1) Run the code I've provided. DO NOT resize the Stage.
      2) Hold down control and click on any CELL in Column 1 (not its header).
      3) This causes all of the invisible columns to become visible, and also it's supposed to scroll to the newly visible column 4.
      4) Unfortunately the scrolling part doesn't happen the first time you control-click. It will happen if you control-click a second time, but shouldn't it happen the first time, too?

      It seems likely that this bug has something to do with the fact that during that first click, Column 4 was made visible immediately before scrollTo() was called. After that, when Column 4 is already visible, everything works as expected.




            Unassigned Unassigned
            cbanackjfx Cory Banack (Inactive)
            0 Vote for this issue
            1 Start watching this issue