Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JLIST Store and retreive data to Properties

 
Andraz Poje
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 436
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I save objects in JList with serialization and save them as a value to properties?

 
Andraz Poje
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 479
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used tokenizer to convert String to Array of strings.
Thanks for help.
Resolved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic