I've a subclass of JTable
that uses a custom table model (an implementation of AbstractTableModel
) to manage data.
The problem occurs when I try to delete a row with the method deleteRow
. The row in my table is replaced by a blank string but the row is not deleted.
Here is the code:
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();
}
}