want to add rows from database in custom table model

Hello all,

I have written custom table model which has single blank row intially.

Once user clicks on button, i want to add more rows in custom table model and display them in JTable.

I have created JTable object as shown below.

Jtable patientTable = new JTable( new DiagnosticTableModel());

My custom tabel model is as shown below.

import javax.swing.table.AbstractTableModel;

publicclass DiagnosticTableModelextends AbstractTableModel

{

private String[] columnNames ={

"Date",

"Diagnosis",

"Severity",

"Medications"};

private String[][] data ={

{"","","",""}

};

publicint getColumnCount()

{

return columnNames.length;

}

publicint getRowCount()

{

return data.length;

}

public String getColumnName(int col)

{

return columnNames[col];

}

public Class getColumnClass(int col)

{

return getValueAt(0, col).getClass();

}

public Object getValueAt(int row,int col)

{

return data[row][col];

}

publicboolean isCellEditable(int row,int col)

{

returntrue;

}

publicvoid setValueAt(Object value,int row,int col)

{

data[row][col] = value.toString();

fireTableCellUpdated(row, col);

}

}

Thanx a lot in advance.

[3272 byte] By [sunny@javaa] at [2007-10-3 8:39:24]
# 1
> I have written custom table model which has single blank row intially.Why did you write a custom TableModel? The DefaultTableModel will work fine and it has methods that allow you to dynamically add rows to the table.
camickra at 2007-7-15 3:47:30 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanx a lot
sunny@javaa at 2007-7-15 3:47:30 > top of Java-index,Desktop,Core GUI APIs...
# 3
1Message was edited by: sunny@java
sunny@javaa at 2007-7-15 3:47:30 > top of Java-index,Desktop,Core GUI APIs...