I have a JButton
which, once it is pressed, adds a row into a JTable
. I have tried to make this by implementing the following code.
columNames = new Vector<>();
columNames.addElement("Name");
columNames.addElement("CC");
columNames.addElement("Age");
columNames.addElement("PhoneNumber");
columNames.addElement("Date");
columNames.addElement("Amount$");
Object[] dataList = {"name", "cc", "age", "phone", "date", "amount"};
data = new DefaultTableModel(columNames, 0);
data.addRow(dataList);
table = new JTable(data);
JScrollPane scrollTable = new JScrollPane(table);
scrollTable.setBounds(22, 78, 764, 177);
scrollTable.setViewportView(table);
//ActionListener method!.
if(e.getActionCommand().equals("Add client"))
{
Object[] dataList = {"name", "cc", "age", "phone", "date", "amount"};
data.addRow(dataList);
DefaultTableModel defaut = (DefaultTableModel) table.getModel();
defaut.addRow(dataList);
}
It throws Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException
:-1
How can I solve it?