"Wathen, Dave" schrieb:
> 
> I agree with Paul this shouldn't be happening.  Do you have a
> reference to the table in your subclass of AbstractTableModel
> (either directly or indirectly).  The listeners are transient
> references.
> 

Why do you think they are transient?

Here is the listenerlist declaration of AbstractTableModel

    /** List of listeners */
    protected EventListenerList listenerList = new EventListenerList();

And here is the actual storage in EventListenerList

    protected transient Object[] listenerList = NULL_ARRAY;

true, it's transient, but only to be able to write all the listeners
manually to the objectoutpstream in case some of them are not
serializable:

    private void writeObject(ObjectOutputStream s) throws IOException {
        Object[] lList = listenerList;
        s.defaultWriteObject();
        
        // Save the non-null event listeners:
        for (int i = 0; i < lList.length; i+=2) {
            Class t = (Class)lList[i];
            EventListener l = (EventListener)lList[i+1];
            if ((l!=null) && (l instanceof Serializable)) {
                s.writeObject(t.getName());
                s.writeObject(l);
            }
        }
        
        s.writeObject(null);
    }

In total: every listener is serialized to the outputstream....

I ran into a similar problem some time ago, and after some research it
turned that I had a misconception of what writeObject() is supposed to
do: I thought I could customize the actual writing in writeObject to any
variable (including supers), but in fact at the point of entry into the
method all of super writeObject() are already done - so every every non
transient variable is already written to the Stream.
 
To solve the original problem, I implemented the actual
adding/removing/notification of TableModelEvents inside a class
TableModelSupport (in analogy to PropertyChangeSupport in java.beans)
and let my custom table model have a transient variable to that support.
Now it's possible to use fine grained control about which listeners are
written and which are not. Don't forget to initialze the support on
readObject(). If the custom derives from some AbstractTableModel (I
often customize DefaultTableModel) then make sure to overwrite
add/removeTableModelListener/fireTableChanged(TableModelEvent e) to
delegate to TableModelSupport. 

Greetings
Jeanette

_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to