Java JTable Data getStringValueAt(JTable table, int row, int columnIndex)

Here you can find the source of getStringValueAt(JTable table, int row, int columnIndex)

Description

get String Value At

License

Open Source License

Declaration

public static String getStringValueAt(JTable table, int row,
            int columnIndex) 

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 String getStringValueAt(JTable table, int columnIndex) {
        return getStringValueAt(table, table.getSelectedRow(), columnIndex);
    }/*from   w ww .j  a v a2s. c  o m*/

    public static String getStringValueAt(JTable table, int row,
            int columnIndex) {
        return String.valueOf(table.getValueAt(row, columnIndex));
    }

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

        if (selectedRow == -1) {
            return null;
        }

        return getStringValueAt(table, selectedRow, columnTitle);
    }

    public static String getStringValueAt(JTable table, int row,
            String columnTitle) {
        return String.valueOf(getValueAt(table, row, columnTitle));
    }

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

        if (selectedRow == -1) {
            return null;
        }

        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. getRenderedComponent(JTable table, Object value, int row, int column)
  2. getRowByValue(TableModel model, int columnIndex, Object value)
  3. getRowIndex(JTable table, int column, String value)
  4. getSelectedValues(JTable table, int column)
  5. getSelectValue(JTable table, String columnName)
  6. getValueAt(JTable table, int row, String columnTitle)
  7. getValueBySelectedRow(JTable table, int rows[], int col)
  8. retrieveSelectedValuesFromTable(JTable table, int column)
  9. selectRows(JTable table, String[] values, int column)