OK so after about 8 more hours of banging my head against the wall, I found out 2 things:
I don't need an action listener on the jtextfield because the JTable takes care of that for me. When I hit
enter
after double clicking + typing OR single-click + typing, JTable automatically callsstopCellEditing()
, which brings me toI need to override
stopCellEditing()
in my IndexerCellEditor class to save the JTextField text before passing it up to the parent. The code I was missing:@Override public boolean stopCellEditing(){ currentValue = textField.getText(); return super.stopCellEditing(); }
Hope this helps anyone with the same problem.
EDIT
This works in my case because I also extended DefaultTableModel
, which takes care of notifying the listeners with the method:
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
cells[rowIndex][columnIndex] = (String) aValue;
fireTableCellUpdated(rowIndex, columnIndex);
}
I tested this some more by building two different tables with the same extended DefaultTableModel
. Placing them side-by-side in a JPanel
, I could edit one cell in one table and upon pressing enter, it would update both the edited cell and its counterpart cell in the other table. In short, the listeners DO need to be notified with a fire...
method call somewhere in the project.