Java JTable Data getRowIndex(JTable table, int column, String value)

Here you can find the source of getRowIndex(JTable table, int column, String value)

Description

get Row Index

License

Open Source License

Declaration

public static int getRowIndex(JTable table, int column, String value) 

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 int getRowIndex(JTable table, int column, String value) {
        int rowCount = table.getModel().getRowCount();

        for (int row = 0; row < rowCount; row++) {
            if (table.getModel().getValueAt(row, column).equals(value)) {
                return row;
            }//from   ww  w.  j  av  a2s. c  o  m
        }

        return -1;
    }

    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. addMissingRows(DefaultTableModel model, String[] values, int column)
  2. columnContains(TableModel table, int colIdx, T... values)
  3. findFirstRow(TableModel model, int col, String value)
  4. getRenderedComponent(JTable table, Object value, int row, int column)
  5. getRowByValue(TableModel model, int columnIndex, Object value)
  6. getSelectedValues(JTable table, int column)
  7. getSelectValue(JTable table, String columnName)
  8. getStringValueAt(JTable table, int row, int columnIndex)
  9. getValueAt(JTable table, int row, String columnTitle)