Java examples for Swing:JTable
get Value from JTable
//package com.java2s; import javax.swing.JTable; import javax.swing.table.TableColumnModel; public class Main { public static Object getValue(JTable table, Object header) { int row = table.getSelectedRow(); return getValue(table, header, row); }//w w w .j a v a2 s . c o m public static Object getValue(JTable table, Object header, int row) { TableColumnModel model = table.getTableHeader().getColumnModel(); int count = model.getColumnCount(); Object result = null; if (-1 == row) return result; for (int i = 0; i < count; i++) { if (model.getColumn(i).getHeaderValue().equals(header)) { result = table.getValueAt(row, i); } } return result; } }