Ok. I have a large project where a particular jtable is created at startup and never gets rebuilt. The table model is refreshed and the table redrawn based on various user actions.
I've added a custom TableCellListener class to react to cell changes along with an AbstractAction. Here is the code that gets executed the first time the table is populated with data. (Without the 'firstLoad' check, multiple actions were getting attached every time the table was redrawn).
if(firstLoad) {
AbstractAction action = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
TableCellListener tcl = (TableCellListener)e.getSource();
sayIt("Row:" + tcl.getRow()+" Column:" + tcl.getColumn()+
" Old:" + tcl.getOldValue()+" New:" + tcl.getNewValue());
}
};
firstLoad = false;
TableCellListener tcl = new TableCellListener(table2, action);
}
TableCellListener is a custom listener posted here by Rob Camick and the 'sayIt' bit is my own debuging code.
This all works great but I would like to remove the listener completely each time the table is rebuilt and add it in again because it is 'remembering' the value from the last selected cell, which is now not valid because the table data is new.
I'm fairly sure a 'removePropertyChangeListener()' type call would do it but it expects the listener as an argument and I'm not sure how to find it.