Java Utililty Methods JTable Data

List of utility methods to do JTable Data

Description

The list of methods to do JTable Data are organized into topic(s).

Method

intaddMissingRows(DefaultTableModel model, String[] values, int column)
For each value in the input array that does not appear in the specified column of at least one of the table model's rows, a new row is added with that value in the specified column and the empty string in the remaining columns.
int numInserted = 0;
if ((values != null) && (model != null)) {
    int columnCount = model.getColumnCount();
    if ((column >= 0) && (column < columnCount)) {
        Set existingValues = new HashSet();
        int rowCount = model.getRowCount();
        for (int row = 0; row < rowCount; row++) {
            existingValues.add(model.getValueAt(row, column));
...
booleancolumnContains(TableModel table, int colIdx, T... values)
column Contains
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;
intfindFirstRow(TableModel model, int col, String value)
Finds the first row of a TableModel that contains a specific String value in a given column.
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;
ComponentgetRenderedComponent(JTable table, Object value, int row, int column)
get Rendered Component
return table.getCellRenderer(0, column).getTableCellRendererComponent(table, value, false, false, row,
        column);
IntegergetRowByValue(TableModel model, int columnIndex, Object value)
get Row By Value
for (int i = model.getRowCount() - 1; i >= 0; --i) {
    if (model.getValueAt(i, columnIndex).equals(value)) {
        return i;
return null;
intgetRowIndex(JTable table, int column, String value)
get Row Index
int rowCount = table.getModel().getRowCount();
for (int row = 0; row < rowCount; row++) {
    if (table.getModel().getValueAt(row, column).equals(value)) {
        return row;
return -1;
String[]getSelectedValues(JTable table, int column)
Returns the value of the specified column for each row currently selected in the table.
String[] selectedValues = new String[0];
if (table != null) {
    int columnCount = table.getColumnCount();
    if ((column >= 0) && (column < columnCount)) {
        int[] selectedRows = table.getSelectedRows();
        selectedValues = new String[selectedRows.length];
        for (int i = 0; i < selectedRows.length; i++) {
            selectedValues[i] = (String) table.getValueAt(selectedRows[i], column);
...
StringgetSelectValue(JTable table, String columnName)
get Select Value
int row = table.getSelectedRow();
if (row >= table.getModel().getRowCount())
    return null;
if (row == -1)
    return null;
int column = table.getColumn(columnName).getModelIndex();
String id = (String) table.getValueAt(row, column);
return id;
...
StringgetStringValueAt(JTable table, int row, int columnIndex)
get String Value At
return String.valueOf(table.getValueAt(row, columnIndex));
ObjectgetValueAt(JTable table, int row, String columnTitle)
get Value At
int column = getColumnIndex(table, columnTitle);
return column == COLUMN_NOT_FOUND ? null : table.getValueAt(row, column);