Java JTable Data setModelValueAt(JTable table, Object value, int row, String columnTitle)

Here you can find the source of setModelValueAt(JTable table, Object value, int row, String columnTitle)

Description

set Model Value At

License

Open Source License

Declaration

public static void setModelValueAt(JTable table, Object value, int row,
            String columnTitle) 

Method Source Code

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

import javax.swing.JTable;

public class Main {
    private static final int COLUMN_NOT_FOUND = -1;

    public static void setModelValueAt(JTable table, Object value, int row,
            int columnIndex) {
        table.getModel().setValueAt(value, row, columnIndex);
    }/*w ww.  j a  v a2  s.c  o  m*/

    public static void setModelValueAt(JTable table, Object value, int row,
            String columnTitle) {
        int column = getColumnIndex(table, columnTitle);

        if (column != COLUMN_NOT_FOUND) {
            table.getModel().setValueAt(value, row, column);
        }
    }

    public static void setValueAt(JTable table, Object value, int row,
            String columnTitle) {
        int column = getColumnIndex(table, columnTitle);

        if (column != COLUMN_NOT_FOUND) {
            table.setValueAt(value, row, column);
        }
    }

    public static int getColumnIndex(JTable table, String columnTitle) {
        int columnCount = table.getColumnCount();

        for (int column = 0; column < columnCount; column++) {
            if (table.getColumnName(column).equalsIgnoreCase(columnTitle)) {
                return column;
            }
        }

        return COLUMN_NOT_FOUND;
    }
}

Related

  1. getValueAt(JTable table, int row, String columnTitle)
  2. getValueBySelectedRow(JTable table, int rows[], int col)
  3. retrieveSelectedValuesFromTable(JTable table, int column)
  4. selectRows(JTable table, String[] values, int column)
  5. selectValueInTable(JTable table, String value, int column)
  6. setValueAt(JTable table, Object value, int row, String columnTitle)
  7. tableColumnValueAlign(JTable table, int column, int align)
  8. updateTable(Object value, int rowId, int columnId, JTable table)