Tim Gordon wrote:
> My guess is that the table model has a reference to the table, which is why
> it is getting serialised along with the model. Most likely candidate is that
> the AbstractTableModel is holding a reference to the table because the table
> is a listener.
>
> Try overriding addTableModelListener() on your subclass of
> AbstractTableModel and put some debug info in there to determine what
> classes are adding themselves as listeners - you will need to remove them
> all before serialising your model.
>
> A quick and dirty way around this might be to maintain a reference to the
> model you wish to serialise and then set a new model on the JTable which is
> looking at your custom model - JTable will have to remove itself as a
> listener to the old model before it listens to the new model.
No. Did not work. Here is the code
// first try
// make EventListenerList to point to null just before
// serializing
private void writeObject( ObjectOutputStream objectOutputStream )
throws IOException
{
EventListenerList llSaved = listenerList ; // protected variable
// in
abstractTableModel
listenerList = null ;
objectOutputStream.defaultWriteObject() ;
listenerList = llSaved ;
}
// second try
// set a dummy model for the listening table
private void writeObject( ObjectOutputStream objectOutputStream )
throws IOException
{
ListeningTable.getInstance().setModel( ( new AbstractTableModel()
{
public int getRowCount()
{
return 3 ;
}
public int getColumnCount()
{
return 3 ;
}
public Object getValueAt(int
row, int column)
{
return null ;
}
}
)
) ;
objectOutputStream.defaultWriteObject() ;
ListeningTable.getInstance().setModel( this ) ;
}
Neither worked. JTable sticks out in the saved file.
Any other ideas pls.
ganesan
>
>
> Alternatively you could implement clone() on your AbstractTableModel
> subclass to just copy your private data (and not the listeners) and then
> serialise.
>
> Lots of things to try.
>
> Tim
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
> J.Ganesan
> Sent: 03 March 2001 06:36
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: AbstractTableModel serialization problem
>
> Hi all,
> I have a class X , which extends AbstractTableModel. When I save an
> object of X, the JTable whose TableModel is the object of X, is also
> serialized and saved. I am interseted ONLY in the private data of X.
> Besides, the file size becomes unacceptably big.
> Any suggestions to solve this problem ?
> Thanks.
>
> ganesan
>
> _______________________________________________
> Swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/swing
>
> _______________________________________________
> Swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/swing
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing