Java JTable Row getRowByValue(TableModel model, Object value)

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

Description

get Row By Value

License

Open Source License

Declaration

public static int getRowByValue(TableModel model, 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 ww w. jav  a2  s  .c  om
            }
        }
        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. getModelRowAtPoint(JTable table, Point point)
  2. getNullRow(TableModel tm)
  3. getReadableRow(JTable table, int maximumHiddenPart)
  4. getRealRowPos(int rowPos, JTable table)
  5. getRowBounds(JTable table, int first, int last)
  6. getTableRow(TableModel tableModel, int row)
  7. hasRows(JTable table)
  8. insertRow(final JTable table, final int index, Object... data)
  9. isFirstToLastRow(TableModelEvent e)