Java JTable Data columnContains(TableModel table, int colIdx, T... values)

Here you can find the source of columnContains(TableModel table, int colIdx, T... values)

Description

column Contains

License

Open Source License

Declaration

public static <T> boolean columnContains(TableModel table, int colIdx,
            T... values) 

Method Source Code

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

import java.util.Arrays;
import java.util.HashSet;

import javax.swing.table.TableModel;

public class Main {
    public static <T> boolean columnContains(TableModel table, int colIdx,
            T... values) {/*from w w  w .  j  a  va 2s.c o  m*/
        HashSet<T> set = new HashSet<T>();
        set.addAll(Arrays.asList(values));
        for (int i = 0; i < table.getRowCount(); i++) {
            set.remove(table.getValueAt(i, colIdx));
            if (set.isEmpty()) {
                return true;
            }
        }
        return false;
    }

    public static <T> boolean columnContains(TableModel table, int colIdx,
            T value) {
        for (int i = 0; i < table.getRowCount(); i++) {
            if (value.equals(table.getValueAt(i, colIdx))) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. addMissingRows(DefaultTableModel model, String[] values, int column)
  2. findFirstRow(TableModel model, int col, String value)
  3. getRenderedComponent(JTable table, Object value, int row, int column)
  4. getRowByValue(TableModel model, int columnIndex, Object value)
  5. getRowIndex(JTable table, int column, String value)