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

voidscrollToRow(JTable table, int row)
scroll To Row
if (!(table.getParent() instanceof JViewport)) {
    return;
JViewport viewport = (JViewport) table.getParent();
Rectangle rect = table.getCellRect(row, 0, true);
Point pt = viewport.getViewPosition();
rect.setLocation(rect.x - pt.x, rect.y - pt.y);
viewport.scrollRectToVisible(rect);
...
voidscrollToSelectedRow(JTable table)
scroll To Selected Row
JViewport viewport = (JViewport) table.getParent();
Rectangle cellRectangle = table.getCellRect(table.getSelectedRow(), 0, true);
Rectangle visibleRectangle = viewport.getVisibleRect();
SwingUtilities.invokeLater(() -> table.scrollRectToVisible(new Rectangle(cellRectangle.x, cellRectangle.y,
        (int) visibleRectangle.getWidth(), (int) visibleRectangle.getHeight())));
voidscrollToTableCell(JTable table, int rowIndex, int colIndex)
scroll To Table Cell
if (!(table.getParent() instanceof JViewport))
    return;
JViewport viewport = (JViewport) table.getParent();
Rectangle rect = table.getCellRect(rowIndex, colIndex, true);
Point p = viewport.getViewPosition();
rect.setLocation(rect.x - p.x, rect.y - p.y);
table.scrollRectToVisible(rect);
voidscrollToVisible(final JTable table, final int rowIndex, final int vColIndex)
scroll To Visible
if (!(table.getParent() instanceof JViewport)) {
    return;
final JViewport viewport = (JViewport) table.getParent();
final Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
final Point pt = viewport.getViewPosition();
rect.setLocation(rect.x - pt.x, rect.y - pt.y);
viewport.scrollRectToVisible(rect);
...
voidscrollToVisible(final JTable table, final int rowIndex, final int vColIndex)
Ensure that a particular table cell is visible.
if (!(table.getParent() instanceof JViewport)) {
    return;
JViewport viewport = (JViewport) table.getParent();
final Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
final Point pt = viewport.getViewPosition();
rect.setLocation(rect.x - pt.x, rect.y - pt.y);
viewport.scrollRectToVisible(rect);
...
voidscrollToVisible(final JTable table, int rowIndex, int vColIndex)
scroll To Visible
if (table == null || !(table.getParent() instanceof JViewport)) {
    return;
JViewport viewport = (JViewport) table.getParent();
try {
    final Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
    Point pt = viewport.getViewPosition();
    rect.setLocation(rect.x - pt.x, rect.y - pt.y);
...
voidscrollToVisible(JTable table, int row, int col)
Assumes table is contained in a JScrollPane.
if (!(table.getParent() instanceof JViewport))
    return;
JViewport viewport = (JViewport) table.getParent();
Rectangle rect = table.getCellRect(row, col, true);
Point pt = viewport.getViewPosition();
rect.setLocation(rect.x - pt.x, rect.y - pt.y);
viewport.scrollRectToVisible(rect);
voidscrollToVisible(JTable table, int row, int col)
Assumes table is contained in a JScrollPane.
if (!(table.getParent() instanceof JViewport))
    return;
JViewport viewport = (JViewport) table.getParent();
Rectangle rect = table.getCellRect(row, col, true);
Point pt = viewport.getViewPosition();
rect.setLocation(rect.x - pt.x, rect.y - pt.y);
viewport.scrollRectToVisible(rect);
voidscrollToVisible(JTable table, int rowIndex, int colIndex)
scroll To Visible
Rectangle rect = table.getCellRect(rowIndex, colIndex, true);
table.scrollRectToVisible(rect);
voidscrollToVisible(JTable table, int rowIndex, int colIndex, boolean center)
scroll To Visible
if (!(table.getParent() instanceof JViewport)) {
    return;
JViewport viewport = (JViewport) table.getParent();
Rectangle rect = table.getCellRect(rowIndex, colIndex, true);
Rectangle viewRect = viewport.getViewRect();
rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y);
if (center) {
...