Binding two tableviews together such that they scroll in sync


I want to bind two tableviews together such that they scroll in sync. How do I do that? I am unable to find out how to access the scrollbar of a tableview.

9/22/2012 6:41:28 AM

I've made a CSS hack to bind a Tableview with an external scrollbar. One scrollbar controls both tableviews.

An overview of my idea:

  • Create two tableviews
  • Make one Vertical scrollbar. Let's call it myScrollbar in this example
  • Set the min and max of myScrollbar to size of min=0, max=TableView.Items.size()
  • When the value of myScrollbar changes then call both tableview's scrollTo(int) function
  • Disable the native vertical scrollbar of the tableview implemented with CSS.

This will give you two tables, both controlled by one external scrollbar (myScrollbar).

Here is the code to hide the scrollbar of a tableview using css:

/* The main scrollbar **track** CSS class  */

.mytableview .scroll-bar:vertical .track{
    -fx-background-radius: 0em;


/* The increment and decrement button CSS class of scrollbar */

.mytableview .scroll-bar:vertical .increment-button ,
.mytableview .scroll-bar:vertical .decrement-button {

    -fx-background-radius: 0em;
    -fx-padding:0 0 0 0;

.mytableview  .scroll-bar:vertical .increment-arrow,
.mytableview  .scroll-bar:vertical  .decrement-arrow
    -fx-shape: " "; 

/* The main scrollbar **thumb** CSS class which we drag every time (movable) */
.mytableview .scroll-bar:vertical .thumb {
    -fx-background-insets: 0, 0, 0;
    -fx-background-radius: 2em;


Then we need to set how to scroll the tableview by using the scrollbar.

scroll.setMax(100); //make sure the max is equal to the size of the table row data.
scroll.valueProperty().addListener(new ChangeListener(){

    public void changed(ObservableValue ov, Number t, Number t1) {
        //Scroll your tableview according to the table row index


9/26/2012 7:37:19 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow