When i try to delete the last row in Jtble it throws me an OutBound error.
here the code that implements the Jtable & DefaultTable:
Vector<String> rowOne = new Vector<>();
rowOne.addElement("Harry");
rowOne.addElement("100414");
rowOne.addElement("21");
rowOne.addElement("239438");
rowOne.addElement("24/24/23");
rowOne.addElement("30000");
Vector<String> rowTwo = new Vector<>();
rowTwo.addElement("Gordon");
rowTwo.addElement("34353");
rowTwo.addElement("25");
rowTwo.addElement("2538");
rowTwo.addElement("24/24/23");
rowTwo.addElement("20000");
Vector<Vector> rowData = new Vector<>();
rowData.addElement(rowOne);
rowData.addElement(rowTwo);
columnNames = new Vector<>();
columnNames.addElement("Name");
columnNames.addElement("Cc");
columnNames.addElement("Age");
columnNames.addElement("Phone");
columnNames.addElement("Date");
columnNames.addElement("Amount");
DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
Jtable table = new JTable(model);
Here the deleting code:
else if (e.getActionCommand().equals("deleteClient"))
{
if(table.getSelectedRow() != -1)
{
DefaultTableModel tModel1 = (DefaultTableModel) table.getModel();
int seletedRow = table.getSelectedRow();
tModel1.removeRow(seletedRow);
}
The error is thrown just when deleting the last Jtable's row, when I delete a diferent row as first one or a middle one, no error is thrown, how can i solve it?
See Question&Answers more detail:os