这是我的tableModel:
public class d9tableModel extends AbstractTableModel { ArrayList<String> cols = new ArrayList<>(); ArrayList<ArrayList<String>> data = new ArrayList<>(); public d9tableModel() { // initial cols and data with database } @Override public int getRowCount() { return data.size(); } @Override public int getColumnCount() { return cols.size(); } @Override public Object getValueAt(int rowIndex, int columnIndex) { ArrayList<String> selectedRow = data.get(rowIndex); return selectedRow.get(columnIndex); } @Override public String getColumnName(int column) { return cols.get(column); } public void removeRow(int rowNumber) { data.remove(rowNumber); } }
现在,在传递convertRowIndexToModel行号之后,请勿删除行!
convertRowIndexToModel
改变这个
public void removeRow(int rowNumber) { data.remove(rowNumber); }
至
public void removeRow(int rowNumber) { data.remove(rowNumber); fireTableRowsDeleted(rowNumber, rowNumber); }