Re: Adding custom cell renderer to JTable causes delete problems
- From: katjapanisch@xxxxxxxxx
- Date: 27 Apr 2007 05:53:07 -0700
On 27 Apr., 11:36, Lionel van den Berg <lione...@xxxxxxxxx> wrote:
Can anyone tell me what the problem is? If I remove the row
tc.setCellEditor(new JTextFieldTableCellEditor()); it doesn't throw the
exception.
If you select the row by clicking on an editable cell, your cell
editor is not stopped before the row is deleted.
Try stopping the active cell editor in your action listener before
deleting.
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int rowNumber = table.getSelectedRow();
TableCellEditor editor = table.getCellEditor();
if (editor != null) {
editor.stopCellEditing();
}
((TestTableModel)
table.getModel()).deleteRow(rowNumber);
}
});
Otherwise, the selection of a new cell after row deletion will stop
the cell editor in the deleted
row, and JTable.editingStopped tries to set the new value for the
edited cell in a row that no longer exists.
If you don't set a custom cell editor, DefaultCellEditor will be used.
Because DefaultCellEditor stops cell editing on actionPerformed,
the exception does not occur.
Katja
.
- Follow-Ups:
- Re: Adding custom cell renderer to JTable causes delete problems
- From: Lionel van den Berg
- Re: Adding custom cell renderer to JTable causes delete problems
- References:
- Adding custom cell renderer to JTable causes delete problems
- From: Lionel van den Berg
- Adding custom cell renderer to JTable causes delete problems
- Prev by Date: Adding custom cell renderer to JTable causes delete problems
- Next by Date: Re: Combinig 2 GUI's to compile and run at the same time.
- Previous by thread: Adding custom cell renderer to JTable causes delete problems
- Next by thread: Re: Adding custom cell renderer to JTable causes delete problems
- Index(es):