I have a very annoying problem in my MVC design and have no clue at all why it happen.
The problem is as follow:
When I try to delete a row from my JTable it works perfect unless I delete the last row. While for all other row the next row is selected, this is not the case for the last row. Hence when I delete the last row, there is no selected row after.
If someone again click on the Delete button the table.getSelectedRow() method should return -1 as there are no rows selected.
Unfortunately, this is not the case and the method return the last stored selected row say 3 for example . As a consequence the program run into an exception.
To make things a little bit tangible I post a simple JTabletest program on a MVC base.
To reproduce the error do the following:
1. Start SimpleJTableTest
2. Select last row in table
3. Click on the Delete button, the selected row index is shown, click OK, the row becomes removed from the view and the model, no other remaining row is selected.
4. Click on the Select button, the selected row index -1 should be presented and that's the problem.
Point 4. is the annoying problem. I don't know why the select row is not -1 .