Here you can find the source of getSelectedValues(JTable table, int column)
Parameter | Description |
---|---|
table | the table |
column | the column of interest |
public static String[] getSelectedValues(JTable table, int column)
//package com.java2s; /*//from w ww . java 2s. c om TSAFE Prototype: A decision support tool for air traffic controllers Copyright (C) 2003 Gregory D. Dennis 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import javax.swing.JTable; public class Main { /** * Returns the value of the specified column for each row * currently selected in the table. * * @param table the table * @param column the column of interest * @return an array of Strings */ public static String[] getSelectedValues(JTable table, int column) { String[] selectedValues = new String[0]; // Make sure the input parameters are valid. if (table != null) { int columnCount = table.getColumnCount(); if ((column >= 0) && (column < columnCount)) { // Get the indices of all selected rows, then extract the // value at the specified column for each row. int[] selectedRows = table.getSelectedRows(); selectedValues = new String[selectedRows.length]; for (int i = 0; i < selectedRows.length; i++) { selectedValues[i] = (String) table.getValueAt(selectedRows[i], column); } } } return selectedValues; } }