GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes serializing subclass of JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "serializing subclass of JScrollPane" Watch "serializing subclass of JScrollPane" New topic
Author

serializing subclass of JScrollPane

Alan Shiers
Ranch Hand

Joined: Sep 24, 2003
Posts: 237
Hi there,

Please help me to properly set up serialization/deserialization of a
subclass of JScrollPane. I called the class Listbox. It extends JScrollPane
implements Serializable and contains a JList object. I have a start on this
but I'm not getting the results I need. Without implementing readObject(...)
and writeObject(...) methods, I keep losing the text inside the JList. It's
still there, just that it disappears everytime I do a save.

I tried implementing the readObject(...) and writeObject(...) methods, but
the text in the JList still keeps disappearing after every save to file and
the visual component of the JScrollPane goes missing when I open a saved
file.

Below is my class Listbox.

Please advise,

Alan

*************************************************
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8915
    
    8

I see you are having trouble getting an answer to this question. Most people here won't even look at a question if it has more than 10-20 lines of code attached to it. We're all volunteers here, and most of us answer the easiest questions first. If your question has a lot of code and is pretty obscure (i.e. serializing GUI components) it may never get answered.
As I see it, you can do two things from here:
1. Help us help you. Simplify your code as much as possible. Narrow your problem down to a test case which exhibits the behavior you find puzzling, but is small enough that people can scan it in a few seconds. This may seem troublesome, but compare it to not getting any help. And you may actually discover a solution when you try to rewrite problem code. Happens to me a lot.
2. Help yourself. Serialization of GUI object is not recommended. Look at the Java API Documentation for pretty much any GUI class and you'll see the following:

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing.

That's enough to scare me away from ever serializing a Swing object because I can't tell a client not to upgrade his JVM. Besides, what you want to persist is data, not presentation. Figure out how to serialize (or otherwise store) your data. Your implementation will be closer to the intended use of the language. Your application will be better segmented and easier to debug. Your problems will be isolated in a small part of your code, making it easier to test and more convient to post here.
Good luck.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
GeeCON Prague 2014
 
subject: serializing subclass of JScrollPane