Java Utililty Methods JTable Scroll

List of utility methods to do JTable Scroll

Description

The list of methods to do JTable Scroll are organized into topic(s).

Method

voidtableCenterScroll(JPanel panel, JTable table, int row)
Scrolls the given table such that the given row will be centered.
JScrollPane scrollPane = (JScrollPane) table.getParent().getParent();
JScrollBar bar = scrollPane.getVerticalScrollBar();
int beforeScrollValue = bar.getValue();
Rectangle r = table.getCellRect(row, 0, true);
table.scrollRectToVisible(r);
panel.repaint();
int afterScrollValue = bar.getValue();
double visibleRowsCount = computeVisibleRowsCount(table);
...
voidupdateScrollMode(JScrollPane scroll, JTable table)
Checks the size of the table and of the scroll bar where it is contained, and depending on it updates the auto resize mode.
int width1 = table.getPreferredScrollableViewportSize().width;
int width2 = scroll.getViewport().getWidth();
if (width1 > width2) {
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
} else {
    table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);