Forums Register Login

Serialize GUI (Swing)

+Pie Number of slices to send: Send
Hy , i have the following issue :
I try to save a JFrame so it's layout and component locations are saved in a configuration file file.







When i try to serialize that frame i get "NotSerializableException" on docker engine thou it's transient (isn't the point of transient to make fields not to be serialized?)

I did try to make that engine implement Serializable interface , then i get

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTabbedPaneUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at srcp.ui.docking.DockingTabbedPane.paintComponent(DockingTabbedPane.java:425)

which i have no idea where comes from.

If you have other ideas about how to save that info , any suggestions are welcome.

Cheers mates ,
and Thanks
+Pie Number of slices to send: Send
DockerEngine is not marked as transient
+Pie Number of slices to send: Send
 

Pierre Sugar wrote:DockerEngine is not marked as transient



I removed it , but with a transient docker engine i get the

java.io.NotSerializableException: srcp.ui.docking.DockerEngine
at java.io.ObjectOutputStream.writeObject0(Unknown Source)

and

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTabbedPaneUI.paint(Unknown Source)

ok , second exception i dont know it's source , but the first....
im not serializing it , why does it throw NotSerializableException maybe it's somehow related to the fact that i have a thread inside it (not plausible at all but this is the only thing that makes this class special :P )
+Pie Number of slices to send: Send
I guess that the DockerEngine hooks itself somehow into the frame it is used with (most probably it registered itself as a listener somewhere). Even if you declare your reference as transient, it is being serialized due to other references deep in the structure of Swing objects.
+Pie Number of slices to send: Send
Interesting fact :

In my concrete case : BaseForm extends DockingFrame
DockingFrame extends JFrame implements Serializable
agregates DockerEngine


When i serialize new DockingFrame it works
When i serialize BaseForm it fails (like described above)

Any one got a clue why this is happening ?
+Pie Number of slices to send: Send
Hi,

Some Serialization basics:

1. Every serialized class should implement either Serializable or Externalizable
2. All non-static non-transient objects members reachable from saved object should be serializable
3. If a class doesn't implement Serializable or Externalizable directly (though its super class implements), any data member that is not serializable will result in NotSerializableException
4. Thread objects are not serializable and any reference by the saved object will cause NotSerializableException
5. Marking a non-serializable field as 'transient' for sure skips it during serialization and should not cause any issues
6. A class should not depend on super classes or subclasses for it's serialization to work properly. It has to take care of everything itself

So, unless you give us the complete source code of the class in question, we can't debug your issue.
Won't you be my neighbor? - Fred Rogers. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4601 times.
Similar Threads
java.io. NotSerializableException: java.awt.TexturePaint
Question on serialization !
Getting error while serializing. Please see the following code while produces IOException.
Deserialization - Cause of WriteAbortedException question
DnD with JLabel subclass
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:15:07.