I have a JTable with 5 rows at the time of design. Now i have to add more rows as i go dynamically. I am getting array out of bound exception error when i add more rows. How do i solve this issue ?
item_list = new javax.swing.JTable();
item_list.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"No.", "Description", "Cost"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.Float.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
item_list.getColumnModel().getColumn(0).setPreferredWidth(30);
item_list.getColumnModel().getColumn(1).setPreferredWidth(100);
item_list.getColumnModel().getColumn(2).setPreferredWidth(50);
jScrollPane2.setViewportView(item_list);
this works for me