Results 1 to 6 of 6
Thread: Storing objects in a Jlist
- 08-20-2012, 09:59 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 15
- Rep Power
- 0
Storing objects in a Jlist
Hi.
I have a form where i can enter values and add them to a Room object I have created. Now what I want is to have a JList populated by these Room objects so that when I select one item in the JList the data stored in that object is put in the form for editing. ('Im using NetBeans)
My problem is that I can only add Strings to the JList, and cant really se how to "link" these strings to my actual objects.
My list format looks like this "[roomnumber] Roomname", but this is just string parts I pull from the object, and don't really "connect" the item to anything.
Does anyone have any pointers to get me in the right direction? As Im not very experienced with java it might be that JList is not the way to achieve my goal?
Parashurama
- 08-20-2012, 11:56 AM #2
- 08-20-2012, 07:03 PM #3
Member
- Join Date
- Aug 2012
- Posts
- 15
- Rep Power
- 0
Re: Storing objects in a Jlist
Excellent answer! Thanks for making me think.
I just asumed as much since the examples I looked at just used strings. My bad...
Ok, so I added the Room item directly, but I still struggle to have them show up the way I want. They just appear like this in the list : "Editors.Room@d5e270" while I want it like I mentioned in the first post.
Do I set the "visible name" in the Jlist in the same addElement method?
Im using DefaultListModel, but none of the methods in the link below seems to do what I need:
DefaultListModel (Java Platform SE 7 )
Got another pointer for me? :)
Parashurama
- 08-20-2012, 07:36 PM #4
Re: Storing objects in a Jlist
Either override toString() or use a custom renderer.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-20-2012, 08:58 PM #5
Member
- Join Date
- Aug 2012
- Posts
- 15
- Rep Power
- 0
Re: Storing objects in a Jlist
Ok, Ill look into the ListCellRenderer, thanks!
- 08-21-2012, 12:38 AM #6
Member
- Join Date
- Aug 2012
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
JAVA storing objects
By santa in forum New To JavaReplies: 24Last Post: 02-24-2012, 02:53 PM -
Storing objects into an arraylist in a different class?
By tepichi09 in forum New To JavaReplies: 2Last Post: 11-06-2011, 07:19 PM -
Storing objects in an array list?
By Moedig in forum New To JavaReplies: 3Last Post: 10-27-2011, 06:39 PM -
Storing objects
By paul1024 in forum New To JavaReplies: 5Last Post: 04-30-2011, 06:12 AM -
Storing objects directly with db4o
By german in forum JDBCReplies: 0Last Post: 05-12-2009, 08:22 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks