Here you can find the source of setTableSelectedRows(JTable table, int... selectedRows)
public static void setTableSelectedRows(JTable table, int... selectedRows)
//package com.java2s; //License from project: Open Source License import javax.swing.*; public class Main { public static void setTableSelectedRows(JTable table, int... selectedRows) { if (selectedRows.length == 0) { table.clearSelection();/* w ww . ja v a2s. co m*/ } else { table.clearSelection(); for (int selectedRow : selectedRows) { table.addRowSelectionInterval(selectedRow, selectedRow); } } } }