JTable has a method getVisibleRowCount(), which shows the preferred number of rows to display.
I want to determine the actual number of rows currently visible in a JTable. How can I do this?
My current attempt is:
int rowsVisible = table.getSize().getHeight()/table.getRowHeight();
but the value it gives me is quite higher than what I can see.
For example, when there are 10 or 11 rows visible, this gives me a result of 18.
I haven’t tested this, but I would expect when a
JTableis contained in aJScrollPane, you can ask the scrollpane for its viewport usinggetViewPort, and retrieve the size from the viewport.If you divide that height with the row height of the table, you might get a better estimation
is pretty close