View RSS Feed

Java Swing

Creating a Table Model

Rate this Entry
by , 04-26-2012 at 09:45 PM (783 Views)
A table model object is used by every table object for management of the actual data of the table. Interface TableModel shall be implemented by the table model object. If table model object is not provided by the programmer them DefaultTableModel instance is automatically created by the the JTable. This kind of relationship is given below:

SimpleTableDemo uses the JTable constructor to create table model, along with code:
Java Code:
new AbstractTableModel() {
    public String getColumnName(int col) {
        return columnNames[col].toString();
    }
    public int getRowCount() { return rowData.length; }
    public int getColumnCount() { return columnNames.length; }
    public Object getValueAt(int row, int col) {
        return rowData[row][col];
    }
    public boolean isCellEditable(int row, int col)
        { return true; }
    public void setValueAt(Object value, int row, int col) {
        rowData[row][col] = value;
        fireTableCellUpdated(row, col);
    }
}

Submit "Creating a Table Model" to Facebook Submit "Creating a Table Model" to Digg Submit "Creating a Table Model" to del.icio.us Submit "Creating a Table Model" to StumbleUpon Submit "Creating a Table Model" to Google

Categories
JTable

Comments