Java JTable Data retrieveSelectedValuesFromTable(JTable table, int column)

Here you can find the source of retrieveSelectedValuesFromTable(JTable table, int column)

Description

This method retrieves the selected values of a table in the tabbed pane and returns them in a string-array

License

Open Source License

Parameter

Parameter Description
table a reference to the swing-table, from which we want to retrieve the entry
column the column which holds the requested values.

Return

an string-array with all values of the selected table-entries, or null if nothing is selected

Declaration

public static String[] retrieveSelectedValuesFromTable(JTable table,
        int column) 

Method Source Code

//package com.java2s;
/*// w w w . j  av  a2 s.  co m
 * Zettelkasten - nach Luhmann
 ** Copyright (C) 2001-2014 by Daniel L?decke (http://www.danielluedecke.de)
 * 
 * Homepage: http://zettelkasten.danielluedecke.de
 * 
 * 
 * This program 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.
 * 
 * This program 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 this program;
 * if not, see <http://www.gnu.org/licenses/>.
 * 
 * 
 * Dieses Programm ist freie Software. Sie k?nnen es unter den Bedingungen der GNU
 * General Public License, wie von der Free Software Foundation ver?ffentlicht, weitergeben
 * und/oder modifizieren, entweder gem?? Version 3 der Lizenz oder (wenn Sie m?chten)
 * jeder sp?teren Version.
 * 
 * Die Ver?ffentlichung dieses Programms erfolgt in der Hoffnung, da? es Ihnen von Nutzen sein 
 * wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die implizite Garantie der MARKTREIFE oder 
 * der VERWENDBARKEIT F?R EINEN BESTIMMTEN ZWECK. Details finden Sie in der 
 * GNU General Public License.
 * 
 * Sie sollten ein Exemplar der GNU General Public License zusammen mit diesem Programm 
 * erhalten haben. Falls nicht, siehe <http://www.gnu.org/licenses/>.
 */

import javax.swing.JTable;

public class Main {
    /**
     * This method retrieves the selected values of a table in the tabbed pane and returns them in
     * a string-array
     *
     * @param table a reference to the swing-table, from which we want to retrieve the entry
     * @param column the column which holds the requested values.
     * @return an string-array with all values of the selected table-entries, or null if nothing is selected
     */
    public static String[] retrieveSelectedValuesFromTable(JTable table,
            int column) {
        int[] rows = table.getSelectedRows();
        if (rows.length < 1) {
            return null;
        }
        String[] value = new String[rows.length];
        for (int cnt = 0; cnt < rows.length; cnt++) {
            value[cnt] = table.getValueAt(rows[cnt], column).toString();
        }
        return value;
    }
}

Related

  1. getSelectedValues(JTable table, int column)
  2. getSelectValue(JTable table, String columnName)
  3. getStringValueAt(JTable table, int row, int columnIndex)
  4. getValueAt(JTable table, int row, String columnTitle)
  5. getValueBySelectedRow(JTable table, int rows[], int col)
  6. selectRows(JTable table, String[] values, int column)
  7. selectValueInTable(JTable table, String value, int column)
  8. setModelValueAt(JTable table, Object value, int row, String columnTitle)
  9. setValueAt(JTable table, Object value, int row, String columnTitle)