Skip to main content

How to use scrollRectToVisible such that to scroll a JTable with more than one JScrollPane in the hierarchy?

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2010-08-30


I have a JTable inside a JScrollPane (let's call it table's scrollpane), but somewhere up in the hierarchy it happens that I have another JScrollPane (let's call it outer scrollpane).

So based on particular layout scenarios, sometimes the tables's scrollpane has:
-its vertical scrollbar showing
-its horizontal scrollbar not showing

while the outer scrollpane has its horizontal scrollbar showing.

My problem is when I call scrollRectToVisible on my JTable to scroll horizontally, it does nothing because the horizontal scrollbar is not showing (in fact all the table is 'viewable' in its viewport), while in reality the Rect is not 'visible' or 'showing' on the screen because it's not in the visible section of the outer scrollpane.

So the desired behavior is that, the outer scrollpane does the scroll.
So how can I modify the code of scrollRectToVisible to achieve that?

Thanks a lot,