I have a JTable and next to it is a button that calls deleteSelectedRows() , which does exactly what it sounds:
public void deleteSelectedRows() { int[] selected = jTable.getSelectedRows(); for(int i = selected.length - 1; i >= 0; i--) { model.removeRow(selected[i]); } if(model.getRowCount() < 1) { addEmptyRow(); } }
But if the cell was edited when it (and / or the cells above it) were deleted, the edited cell remained, and the rest remained, for example:

And then, trying to get out of editing, threw an ArrayIndexOutOfBoundsException , because row 5 tried to be accessible to it, and only one row remained in the table.
Then I tried all kinds of fun and games using jTable.getEditingRow() . At first, adding if(selected[i] != editing) before the deletion seemed to work, but then deleting the rows above the edited cell caused problems.
Then I tried this:
public void deleteSelectedRows() { int[] selected = jTable.getSelectedRows(); int editing = jTable.getEditingRow(); for(int s : selected) {
But it doesnโt delete anything, never. Judging by println , I sprinkled, the last cell to be selected (which has a special border marked here on spam ) is considered part of the edit line and thus triggers my early return .

So I donโt care if the solution is related to fixing the original problem - due to awkward results, when the deleted cell is deleted - or this new problem - the getEditingRow() problem does not work as I expected, I just need at least one of them. However, I would be interested to hear both decisions only out of academic curiosity. Thanks in advance.
source share