小编典典

TableModel removeRow()定义

java

这是我的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行号之后,请勿删除行!


阅读 266

收藏
2020-12-03

共1个答案

小编典典

改变这个

 public void removeRow(int rowNumber) {
        data.remove(rowNumber);
    }

public void removeRow(int rowNumber) {
    data.remove(rowNumber);
    fireTableRowsDeleted(rowNumber, rowNumber);
}
2020-12-03