Java examples for Swing:JTable Scroll
scroll JTable To Top And Select First
//package com.java2s; import java.awt.Rectangle; import javax.swing.JTable; import javax.swing.JViewport; public class Main { public static void scrollToTopAndSelectFirst(JTable table) { synchronized (table.getModel()) { if (!(table.getParent() instanceof JViewport)) { return; }//from w ww . ja v a 2s . c o m table.scrollRectToVisible(new Rectangle(0, 0, 0, table .getRowHeight())); // select first if (table.getModel().getRowCount() > 0) { table.getSelectionModel().setSelectionInterval(0, 0); } } } }