select JTable Rows - Java Swing

Java examples for Swing:JTable Row

Description

select JTable Rows

Demo Code


//package com.java2s;

import javax.swing.JTable;

public class Main {
    public static void selectRows(JTable table, int[] rowIndexes) {
        table.getSelectionModel().setValueIsAdjusting(true);
        try {/*  w  ww . j  a  va 2  s. c  om*/
            table.clearSelection();
            for (int row : rowIndexes) {
                table.addRowSelectionInterval(row, row);
            }
            if (table.getCellSelectionEnabled()) {
                table.setColumnSelectionInterval(0,
                        table.getColumnCount() - 1);
            }
        } finally {
            table.getSelectionModel().setValueIsAdjusting(false);
        }
    }
}

Related Tutorials