Jlist - ListModel and CellRenderer

  • Thread starter =?ISO-8859-15?Q?Martin_M=FCcke?=
  • Start date
?

=?ISO-8859-15?Q?Martin_M=FCcke?=

Hi,

I want to create a JList containing a list of objects (containers).
When showing those objects in the list, I want to see a string,
but when working with those Objects of course I need other values,
especially the objects database key as well.
Do I have to implement my own ListModel, or can I do without?
Would you even recomend to use my own CellRenderer, or does a simple
toString() method in my object do?

thanks,

Martin
 
T

Thomas Hawtin

Martin said:
I want to create a JList containing a list of objects (containers).
When showing those objects in the list, I want to see a string,
but when working with those Objects of course I need other values,
especially the objects database key as well.
Do I have to implement my own ListModel, or can I do without?
Would you even recomend to use my own CellRenderer, or does a simple
toString() method in my object do?

Simply providing a toString on the objects will do. If you can't change
the objects themselves then you can write a simple proxy that holds the
original object, but does its own thing with toString.

For anything more complicated you will need a renderer. I suggest
keeping the renderer as simple as possible, putting most of the logic in
the objects themselves (or proxies).

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top