This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes JLIST Store and retreive data to Properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JLIST Store and retreive data to Properties" Watch "JLIST Store and retreive data to Properties" New topic
Author

JLIST Store and retreive data to Properties

Andraz Poje
Ranch Hand

Joined: Sep 25, 2008
Posts: 32
Hi. I want to save/load data in jlist to one key in properties file.
http://www.leepoint.net/notes-java/io/30properties_and_preferences/10properties.html



What is the best way to do this?
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Complete list of rules for using JList:

1. Don't use JList, use JTable instead.

But this just shifts your problem to another component presenting your data. But how does the presentation matter for your problem? - It doesn't. What you need to do is to write an appropriate model (TableModel or ListModel) that is capable of saving the data. You already have a class that is holding the data, the Properties class. So you need a facade that is implementing the TableModel or ListModel interface and can present the data (or you go for a proxy, then you can extend one of the abstract models, which could be easier).

Then for presenting you just need to set the model. For saving you just call the methods for doing so. It would be a bad idea to have different data for presenting and storing and trying to synchronize them.
Andraz Poje
Ranch Hand

Joined: Sep 25, 2008
Posts: 32
Can I save objects in JList with serialization and save them as a value to properties?

Andraz Poje
Ranch Hand

Joined: Sep 25, 2008
Posts: 32
OK, I found stg. How can I use it?

http://stackoverflow.com/questions/134492/how-to-serialize-an-object-into-a-string


I want to save data in my jlist



to string....
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
I think one problem you're going to have is that not every Java class has a generic method for reconstituting itself from a string; there's a method for outputting a string that representst a class -- toString() -- but it has no rules about representing the entire class, much less anything for creating an object instance based on the output.

So unless you are storing classes that you know how to "string-ize" and "un-string-ize" in your list, and you want to write the methods to do it yourself, I think you're out of luck.

rc
Andraz Poje
Ranch Hand

Joined: Sep 25, 2008
Posts: 32
I used tokenizer to convert String to Array of strings.
Thanks for help.
Resolved.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JLIST Store and retreive data to Properties