我有一个JTable
使用自定义表模型(的实现AbstractTableModel
)来管理数据的子类。
当我尝试使用该方法删除一行时会出现问题deleteRow
。我的表中的行被一个空白字符串替换,但该行没有被删除。
这是代码:
public class LiveSearchTableModel extends AbstractTableModel
{
private List<String> columnNames = new ArrayList<String>();
private Map<Point, Object> displayData = new HashMap<Point, Object>();
private Map<Point, Object> originalData = new HashMap<Point, Object>();
public LiveSearchTableModel(List<String> columnNames,
Map<Point, Object> tableData)
{
this.columnNames = columnNames;
this.displayData = tableData;
this.originalData.putAll(tableData);
}
@Override
public int getColumnCount() {
return columnNames.size();
}
@Override
public int getRowCount() {
return displayData.size() / columnNames.size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return displayData.get(new Point(rowIndex, columnIndex));
}
public void deleteRow (int row)
{
for (int cont = 0; cont < columnNames.size();cont++)
{
displayData.remove(new Point (row,cont));
}
this.fireTableRowsDeleted(row, row);
}
@Override
public void setValueAt(Object value, int rowIndex, int columnIndex)
{
this.displayData.put(new Point(rowIndex, columnIndex), value);
this.fireTableDataChanged();
}
}