I have a JTable and I need to remove a row, namely, the selected row.
So first, I get the the table model :
DefaultTableModel model = (DefaultTab
The index returned by JTable.getSelectedRow
is a view
index : it's the index of the row as seen by the end-user in the table. It's not the same as the model index, because if you sort the table, the indices in the model don't change, but the indices in the view do change. So, you must always use JTable.convertRowIndexToModel to get the model index from the view index.
Note that the same must be done for columns, because the user might choose to reorder columns to its taste.
Also, you shouldn't have to set the model again each time you remove a row. Instead, your model should fire a TableModelEvent to inform the view about the removal. See AbstractTableModel.fireTableRowsDeleted.
If is JTable
filtered or sorted then you can convert
int modelRow = convertRowIndexToModel(row);