这是我的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
行号后,请勿删除行!
答案 0 :(得分:1)
更改此
public void removeRow(int rowNumber) {
data.remove(rowNumber);
}
到
public void removeRow(int rowNumber) {
data.remove(rowNumber);
fireTableRowsDeleted(rowNumber, rowNumber);
}