Hi All;
Im just making a simple Desktop app. Ive got a need so that the user could be able to add data to the table dynamically. Ive done implementing the table and also code for adding rows.
Issue is after i add the row it is not displayng in the table. Of course I am addin it to the tableModel and also firing the insert row updated.
The row count shows that it is increased but not siplayed. Any suggestions/help would be highly appreciated
Code initializing the table (Netbeans Used)
jScrollPane1.setName("jScrollPane1"); // NOI18N
Object[] columnName = {"Name","Age","Address"};
Object[][] rowData = {{"a","b","c"}};
tableModel = new DefaultTableModel(columnName,0);
/*
for (int i = 0; i < columnName.length; i++) {
Object object = columnName[i];
tableModel.addColumn(object);
}
for (int i = 0; i < rowData.length; i++) {
Object[] objects = rowData[i];
tableModel.addRow(objects);
}*/
jTable1.setModel(tableModel);
jTable1.setFillsViewportHeight(true);
jTable1.setColumnSelectionAllowed(true);
jTable1.setName("jTable1");
jScrollPane1.setViewportView(jTable1);
jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jPanel1.add(jScrollPane1);
The code which is fired on insert
private void insertNewRow(){
Object[] val = {jTextField1.getText(),jTextField2.getText(),jTextField3.getText()};
tableModel.addRow(val);
tableModel.fireTableRowsInserted(tableModel.getRowCount(),
tableModel.getRowCount());
System.out.println("Row Count : "+tableModel.getRowCount());
}