Forums Register Login

Auto scroll a JTable

+Pie Number of slices to send: Send
I have searched around for a solution to this, but all I have found are solutions from 2002 and the methods they called to achieve this seem to have been removed.

I have the JTable and it fills up like it should, it scrolls correctly, but how do I get it to scroll automatically when a new row is added?
1
+Pie Number of slices to send: Send
after you add the new row

table.scrollRectToVisible(table.getCellRect(table.getRowCount()-1, 0, true));
[ February 28, 2008: Message edited by: Michael Dunn ]
+Pie Number of slices to send: Send
Thank you very much.

The only problem was that it would not autoscroll to the last row, but to the last row -1. Oddly, just passing the actual row count didn't fix the issue but this did:


table.scrollRectToVisible(table.getCellRect(table.getRowCount()-1, table.getColumnCount(), true));

Thanks again!
+Pie Number of slices to send: Send
try the code from my earlier post,
but wrap it in a SwingUtilities.invokeLater

this should give enough time for getRowCount() to update
+Pie Number of slices to send: Send
It works for me. thanks a lot.
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 11867 times.
Similar Threads
JTable in a JViewport
JTable "..."
JTable row
JScrollPane, JTable
JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:33:04.