Selects the first row in a JTable. - Java Swing

Java examples for Swing:JTable Row

Description

Selects the first row in a JTable.

Demo Code


//package com.java2s;

import javax.swing.JTable;

public class Main {
    /**//from   ww w  .  jav  a  2  s  . c  o  m
     * Selects the first row in a table. This method is tolerant, it does
     * nothing if the given table is <code>null</code> or does not contain any
     * row.
     * 
     * @param table
     *            the table to select the first row from.
     */
    public static void selectFirstRow(JTable table) {
        if (table != null && table.getRowCount() > 0) {
            table.getSelectionModel().setSelectionInterval(0, 0);
        }
    }
}

Related Tutorials