Hi all. Excuse me because I am quite new to swing. What I want to do is this: I have these objects "contact", they store info like name, number , email etc, it has getters and setters for these properties. I then have a vector which holds a number of these contact objects.
On my panel I have a Jlist in which I would like to display the name and next to them a couple of text fields which display the number, email etc for the name in the JList. The idea is you select the name in the list and the text fields are updated to show the corrisponding number, email etc.
If I set the list up with the vector of contacts then obviously you see the list of String representations of each contact object.
My question is .. how can I set up the list to show just the name from each contact, but still know which object has been selected? Should I make a seperate String array of names, then when I select them use the index number of the selected name to select the details for the text fields from the contacts vector? ... this seems a bit cumbersome and I am sure that there must be a neater way...
If I havnt been clear let me know and I will try to explain a little better... thanks in advance of any help..
You can implement a custom renderer that will just display the name of the object. I would keep the list itself containing full object references. Here is Sun's JList tutoral. There is a link at the bottom of the article about custom renderers.
You can then add a listener for selection change. On each change get the selected object and populate your values. If you'd like to look at an even easier way to do things, checkout JGoodies Data Binding.
Thanks everyone for your help... I really appreciate the time you took to help me with a solution. I believe I am just about there with it now. I must also say that this is such an invaluable resource...