Java JTable Data getValueAt(JTable table, int row, String columnTitle)

Here you can find the source of getValueAt(JTable table, int row, String columnTitle)

Description

get Value At

License

Open Source License

Declaration

public static Object getValueAt(JTable table, int row,
            String columnTitle) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.JTable;

public class Main {
    private static final int COLUMN_NOT_FOUND = -1;

    public static Object getValueAt(JTable table, String columnTitle) {
        int selectedRow = table.getSelectedRow();

        if (selectedRow == -1) {
            return null;
        }//from w w w.  j a  v  a 2  s.  co  m

        return getValueAt(table, selectedRow, columnTitle);
    }

    public static Object getValueAt(JTable table, int row,
            String columnTitle) {
        int column = getColumnIndex(table, columnTitle);

        return column == COLUMN_NOT_FOUND ? null : table.getValueAt(row,
                column);
    }

    public static int getColumnIndex(JTable table, String columnTitle) {
        int columnCount = table.getColumnCount();

        for (int column = 0; column < columnCount; column++) {
            if (table.getColumnName(column).equalsIgnoreCase(columnTitle)) {
                return column;
            }
        }

        return COLUMN_NOT_FOUND;
    }
}

Related

  1. getRowByValue(TableModel model, int columnIndex, Object value)
  2. getRowIndex(JTable table, int column, String value)
  3. getSelectedValues(JTable table, int column)
  4. getSelectValue(JTable table, String columnName)
  5. getStringValueAt(JTable table, int row, int columnIndex)
  6. getValueBySelectedRow(JTable table, int rows[], int col)
  7. retrieveSelectedValuesFromTable(JTable table, int column)
  8. selectRows(JTable table, String[] values, int column)
  9. selectValueInTable(JTable table, String value, int column)