The behavior is enforced by calling scrollRectToVisible()
from the table's UI delegate, typically derived from BasicTableUI
. Short of supplying your own delegate, you can use setPreferredScrollableViewportSize()
to make the height of enclosing Container
an intergral multiple of the rowHeight
, as shown below and in this example.
private static final int N_ROWS = 8;
private JTable table = new JTable();
...
Dimension d = new Dimension(
table.getPreferredScrollableViewportSize().width,
N_ROWS * table.getRowHeight());
table.setPreferredScrollableViewportSize(d);
add(new JScrollPane(table));
