Here you can find the source of setSelectedRow(JTable table, int rowIndex, int columnIndex)
public static void setSelectedRow(JTable table, int rowIndex, int columnIndex)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.awt.*; public class Main { public static void setSelectedRow(JTable table, int rowIndex, int columnIndex) { table.setRowSelectionInterval(rowIndex, columnIndex); scrollToSelectedRow(table);//from w w w .j ava 2s . c o m } private static void scrollToSelectedRow(JTable table) { 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()))); } }