Java JTable Row Selection selectLastTableRow(JTable table)

Here you can find the source of selectLastTableRow(JTable table)

Description

Select the last row in a table.

License

Open Source License

Parameter

Parameter Description
table a parameter

Declaration

public static void selectLastTableRow(JTable table) 

Method Source Code

//package com.java2s;
/*/*from   w ww.j a v  a2s.c o m*/
 Copyright (C) 2011 Jason von Nieda <jason@vonnieda.org>
    
 This file is part of OpenPnP.
    
 OpenPnP is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 OpenPnP is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with OpenPnP.  If not, see <http://www.gnu.org/licenses/>.
    
 For more information about OpenPnP visit http://openpnp.org
 */

import javax.swing.JTable;

public class Main {
    /**
     * Select the last row in a table. Handy for selecting a row that was
     * just added.
     * @param table
     */
    public static void selectLastTableRow(JTable table) {
        table.clearSelection();
        int index = table.getRowCount() - 1;
        index = table.convertRowIndexToView(index);
        table.addRowSelectionInterval(index, index);
    }
}

Related

  1. fireSelectRow(final JTable table, final int row)
  2. getSelectedModelRow(JTable table)
  3. moveRowSelection(JTable pJTable, int pRow)
  4. removeSelectedRowFromTable(JTable table)
  5. selectClickedRow(final JTable table, final MouseEvent event)
  6. setTableSelectedRows(JTable table, int... selectedRows)
  7. tableModelToArray(JTable table, boolean onlyTheSelectedRows)