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.

