JDK-8194328 : TableView scrolls slightly when adding items
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u151
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2018-01-03
  • Updated: 2018-01-03
  • Resolved: 2018-01-03
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.17.10.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux My-PC 4.13.0-21-generic #24-Ubuntu SMP Mon Dec 18 17:29:16 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


EXTRA RELEVANT SYSTEM CONFIGURATION :
Also occurring on windows 7. 

A DESCRIPTION OF THE PROBLEM :
I have a TableView that has content added to it every 100ms or so, for about 5 or 10 minutes.

While that content is being added, if you aren't at the very top or very bottom of the table, the content scrolls a little bit each time an item is added.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the code below and watch the table

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The table does not scroll
ACTUAL -
The table scrolls slightly

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
TableAutoScroll.java:

import java.util.ArrayList;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class TableAutoScroll extends Application {

    @Override
    public void start( Stage stage ) throws Exception {

        ObservableList<Person> tableContent = FXCollections.observableArrayList( new ArrayList <Person>() );

        TableColumn <Person, String> firstNameColumn = new TableColumn <> ( "First Name" );
        TableColumn <Person, String> LastNameColumn = new TableColumn <> ( "Last Name" );
        TableColumn <Person, String> addressColumn = new TableColumn <> ( "Address" );

        firstNameColumn.setCellValueFactory( new PropertyValueFactory <Person, String>( "firstName" ) );
        LastNameColumn.setCellValueFactory( new PropertyValueFactory <Person, String>( "lastName" ) );
        addressColumn.setCellValueFactory( new PropertyValueFactory <Person, String>( "address" ) );

        TableView <Person> tableView = new TableView <> ();
        tableView.getColumns().addAll( firstNameColumn, LastNameColumn, addressColumn );
        tableView.setColumnResizePolicy( TableView.CONSTRAINED_RESIZE_POLICY );
        tableView.setItems( tableContent );

        for ( int k = 0; k < 500; k ++ ) {
            tableContent.add ( new Person ( "Dummy", "Person", k + " Sesame Street" ) );
        }

        tableView.scrollTo( 200 );

        BorderPane pane = new BorderPane( tableView );
        stage.setScene( new Scene( pane, 800, 400 ) );
        stage.show();

        Thread populateThread = new Thread ( () -> {
            for ( int k = 0; k < 10000; k ++ ) {
                Person addMe = new Person ( "Dummy", "Person", k + " Sesame Street" );
                Platform.runLater( ()-> tableContent.add( addMe ) );
                try {
                    Thread.sleep( 100 );
                } catch (InterruptedException e) {}
            }
        });

        populateThread.setDaemon ( true );
        populateThread.start();

    }

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


Person.java (Must be separate file): 

public class Person {
    private String firstName, lastName, address;

    public Person ( String firstName, String lastName, String address ) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
    }

    public String getFirstName() {
        return firstName;
    } 

    public String getLastName() {
        return lastName;
    }

    public String getAddress() {
        return address;
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I have not yet found one. 


Comments
Issue is reproducible in JDK 8, 9, 10-ea+36. Closing this as duplicate of JDK-8178297, which is in Open state.
03-01-2018