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.
Regards
Dave Wathen
Goldman Sachs Asset Management
3rd Floor, Procession House
55 Ludgate Hill
London EC4M 7JN
+44 (0)20-7774-2998
It is not necessary to understand things in order to argue about them.
(Caron de Beaumarchais)
-----Original Message-----
From: Paul Brinkley [mailto:[EMAIL PROTECTED]]
Sent: Sunday, March 04, 2001 6:09 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: AbstractTableModel serialization problem
At 10:12 PM 3/4/01 +0530, J.Ganesan wrote:
>
>
>Paul Brinkley wrote:
>
>> At 12:05 PM 3/3/01 +0530, J.Ganesan wrote:
>> >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.
>>
>> If you're only interested in an X's private data, you should
>> probably extract it explicitly and save it, rather than
>> trying to serialize the X object itself. The reason for
>> this is that some other class may need to save the state
>> of the entire X object, including any JTables it references.
>
>How can we do this ? Because, even if we implement writeObject() method
>for the private data , the defaultWriteObject() method operates on super
>class .
>With the result that JTable is also serialized.
That's correct. (With the proviso that I still don't know
how this table model is referencing JTable non-transiently.
It was my understanding that event listeners were transient.
Can anyone give a better explanation? Is it because
AbstractTableModel doesn't extent Component? Is there a
John Zukowski in the house? :-) )
The standard way around this is externalization. It's a
more hands-on version of serialization. First, have your
class implement java.io.Externalizable. Then you have to
implement two methods it defines; I can't remember the
names of them off the top of my head, but they're clearly
outlined in the Javadoc for Externalizable. An externalizable
object writes -only- those fields you tell it to in the
"write" method.
The superclass is initialized using its no-arg constructor.
AbstractTableModel happens to have one, so you're fine there.
Again, I'm not certain serialization/externalization is the
"right" approach here, since you're explicitly interested
in saving only the table data. I would implement a method
on X that saves just table data, but that's me.
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing