Here you can find the source of ensureRowVisible(JTable table, int row)
public static void ensureRowVisible(JTable table, int row)
//package com.java2s; //License from project: Open Source License import java.awt.Rectangle; import javax.swing.JTable; public class Main { public static void ensureRowVisible(JTable table, int row) /* */{/* ww w . j a va 2s . co m*/ /* 3297 */Rectangle r = table.getVisibleRect(); /* */ /* 3300 */Rectangle rMid = table.getCellRect(row, 0, true); /* 3301 */Rectangle rBefore = null; Rectangle rAfter = null; /* 3302 */if (row < table.getModel().getRowCount() - 1) /* 3303 */rAfter = table.getCellRect(row + 1, 0, true); /* 3304 */if (row > 0) { /* 3305 */rBefore = table.getCellRect(row - 1, 0, true); /* */} /* 3307 */int yLow = (int) rMid.getMinY(); /* 3308 */int yHi = (int) rMid.getMaxY(); /* 3309 */int xLow = r.x; /* 3310 */int xHi = r.x + r.width; /* */ /* 3312 */if (rBefore != null) { /* 3313 */yLow = (int) rBefore.getMinY(); /* */} /* 3315 */if (rAfter != null) { /* 3316 */yHi = (int) rAfter.getMaxY(); /* */} /* */ /* 3319 */Rectangle rScrollTo = new Rectangle(xLow, yLow, xHi - xLow, yHi - yLow); /* 3320 */if ((!r.contains(rScrollTo)) && (rScrollTo.height != 0)) /* 3321 */table.scrollRectToVisible(rScrollTo); /* */} }