Search code examples
javaswingjtabletablecelleditor

Can a TableCellEditor tell which JTable it is editing?


I have a TableCellEditor that overrides stopCellEditing to validate the content. I would like to interact with the table as part of this validation. Is there a way to determine what table we are editing? I thought it would be getParent(), but it seems sometimes getParent() is the table and other times it's null.


Solution

  •  Component getTableCellEditorComponent(JTable table, Object value,
                                          boolean isSelected,
                                          int row, int column)
    

    The method of TableCellEditor interface has the first parameter JTable instance. SO you can keep the table in a field and use it in the stopCellEditing