I would like to make a JTable which can add rows to itself dynamically,initially the table should have no data in it. I did this by creating a TableModel class extends AbstractTableModel, code is attached.
class MyTableModel extends AbstractTableModel{
private static int initialRowCount = 3;
private ArrayList<ArrayList<Object>> data;
private static String[] columnName = {"Date Tested","Product","VI Test Result","Lot ID","MCN","SLT TIS","Tester","In","First Pass","FP%","RT1 Pass","RT2 Pass","Final Pass",
"SLT Final Yield %","SLT Fail Quantity","Remark"};
int i=0;
public MyTableModel(){
data = new ArrayList<ArrayList<Object>>(20);
}
public int getColumnCount() {
System.out.println(i++);
return columnName.length;
}
public int getRowCount() {
return initialRowCount;
}
public Object getValueAt(int r, int c) {
}
public String getColumnName(int c) {
return columnName[c];
}
public boolean isCellEditable(int row, int column) {
if(column==0)
return false;
else
return true;
}
public void setValueAt(Object vaule,int row,int column){
data.add();
}
public void addRow(){
initialRowCount++;
}
}
My question is, must I use a 2-D ArrayList as a data container? If so, How should I implement it in this code? I am new to Java and just start learning Swing, any help is appreciated.