get Value from JTable - Java Swing

Java examples for Swing:JTable

Description

get Value from JTable

Demo Code


//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;
    }
}

Related Tutorials