javaswingjtablejscrollpanejscrollbar

How to share the same view between two jtable


I have two JTable horizontally positioned that shares the same row selection model. Only the right one is inside aJScrollPane with a vertical scrollbar.

I need to share the same view for both tables, so when necessary, also force the scrollbar to move up or down, to maintain aligned the views.


Solution

  • The problem is that I needed to fix the first column of the JTable (that's why I made two JTables)

    So then you can add the first table as the "row header" of the scrollpane. Then both components will scroll in sync as both the row header and viewport are part of the scroll pane.

    See Fixed Column Table for a reusable implementation of this approach that creates the table uses in the row header for you.