Here you can find the source of scrollToVisible(final JTable table, final int rowIndex, final int vColIndex)
Parameter | Description |
---|---|
table | the table |
rowIndex | the row index |
vColIndex | the column index |
public static void scrollToVisible(final JTable table, final int rowIndex, final int vColIndex)
//package com.java2s; //License from project: Open Source License import java.awt.Point; import java.awt.Rectangle; import javax.swing.JTable; import javax.swing.JViewport; public class Main { /**/*ww w. j a v a 2 s. c o m*/ * Ensure that a particular table cell is visible. * * @param table the table * @param rowIndex the row index * @param vColIndex the column index */ public static void scrollToVisible(final JTable table, final int rowIndex, final int vColIndex) { // Check the parent if (!(table.getParent() instanceof JViewport)) { return; } // Get the parent viewport JViewport viewport = (JViewport) table.getParent(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). final Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); // The location of the viewport relative to the table final Point pt = viewport.getViewPosition(); // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0) rect.setLocation(rect.x - pt.x, rect.y - pt.y); // Scroll the area into view viewport.scrollRectToVisible(rect); } }