Java JTable Data getRowByValue(TableModel model, int columnIndex, Object value)

Here you can find the source of getRowByValue(TableModel model, int columnIndex, Object value)

Description

get Row By Value

License

Open Source License

Declaration

public static Integer getRowByValue(TableModel model, int columnIndex, Object value) 

Method Source Code

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

import javax.swing.table.TableModel;

public class Main {
    public static int getRowByValue(TableModel model, Object value) {
        for (int i = model.getRowCount() - 1; i >= 0; --i) {
            for (int j = model.getColumnCount() - 1; j >= 0; --j) {
                if (model.getValueAt(i, j).equals(value)) {
                    // what if value is not unique?
                    return i;
                }//from  w w  w  .  j av a2 s.  co m
            }
        }
        return 0;
    }

    public static Integer getRowByValue(TableModel model, int columnIndex, Object value) {
        for (int i = model.getRowCount() - 1; i >= 0; --i) {
            if (model.getValueAt(i, columnIndex).equals(value)) {
                return i;
            }
        }
        return null;
    }
}

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. getRowIndex(JTable table, int column, String value)
  6. getSelectedValues(JTable table, int column)
  7. getSelectValue(JTable table, String columnName)
  8. getStringValueAt(JTable table, int row, int columnIndex)