Re: AbstractTableModel - delete not updating rows properly
steve wrote:
because one is indexed from zero , the other from 1.
I don't think that is the case. Here's a snippet of the relevant code:
//delete dose button pressed
private void btnDelDoseActionPerformed(ActionEvent e) {
if(tblHistory.getSelectedRow() == -1) {
tciworks.util.ErrorMessage.warningMessage(
"You must select a dose to delete", "No Dose
Selected");
return;
}
int rowNumber = tblHistory.getSelectedRow();
((DoseHistoryTableModel)tblHistory.getModel()).deleteRow(rowNumber);
}
public class DoseHistoryTableModel {
....
public void deleteRow(int row) {
DoseList doseList = course.getDosingHistory();
Dose dose = doseList.getDose(row);
if(course.doseHasConcRecord(dose)) {
tciworks.util.ErrorMessage.warningMessage(
"There is a concentration recorded for this dose. "
+
"Please ammend the concentration before deleting.",
"Delete Failed");
return;
}
try {
DataStore.deleteDose(dose);
doseList.remove(row);
} catch(DeleteFailedException dfe) {
tciworks.util.ErrorMessage.warningMessage(
"An unknown exception occured and the dose could
not be " +
"deleted!", "Delete Failed");
}
fireTableDataChanged();
}
}
I'm not explicitely telling JTable that something is deleted. It get's
the contents of it's cells using the method I have over-ridden called
getValue(int row, int column).
I hope I'm missing something simple . . .