Search code examples
javaswingjtabletablecelleditor

Cell editor not exiting when row is deleted


I have a JTable with a several columns, one of which is has a custom renderer to display 3 buttons in a JPanel as well as a custom editor to allow them to be clickable. One of the buttons sends a delete command to our server for that row id then reloads the table data from the server by clearing the data model and loading data again. When this happens the cell with the 3 buttons continues to display (but not the rest of the row) until I click another button in another row even though the row is gone.

I've set putClientProperty("terminateEditOnFocusLost", Boolean.TRUE) but changing focus to another component does not help.

I've tried deleting the row itself before refreshing the data (even deleted all the rows) and made sure to call fireTableRowsDeleted().

I've also tried calling the cancelCellEditing() and stopCellEditing() functions of the TableCellEditor and even manually setting the editing row/column to another cell.

Any help would be greatly appreciated.


Ok, so I figured it out. I ended up calling removeEditor() on the table and that fixed it.

Thanks for the responses.


Solution

  • Ok, so I figured it out. I ended up calling removeEditor() on the table just before the data refresh and that fixed it.

    Thanks for the responses.