Here you can find the source of findFirstRow(TableModel model, int col, String value)
Parameter | Description |
---|---|
model | The TableModel to search through |
col | The column index to search under. |
value | The value of the cell to look for. |
public static int findFirstRow(TableModel model, int col, String value)
//package com.java2s; /*//from ww w . j a va2 s. c om * Copyright (c) 2008, SQL Power Group Inc. * * This file is part of Power*Architect. * * Power*Architect is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Power*Architect is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import javax.swing.table.TableModel; public class Main { /** * Finds the first row of a {@link TableModel} that contains a specific * {@link String} value in a given column. Note that all leading and trailing * spaces are trimmed when matching. * * @param model * The {@link TableModel} to search through * @param col * The column index to search under. * @param value * The value of the cell to look for. * @return The index of the matched row or -1 if not found. */ public static int findFirstRow(TableModel model, int col, String value) { String trimmedValue = value.trim(); for (int i = 0; i < model.getRowCount(); i++) { if (((String) model.getValueAt(i, col)).trim().equals( trimmedValue)) { return i; } } return -1; } }