• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Custom CellRenderer

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to create a ComboBox which will be constructed using:

My custom Combobox model will contain a Map (key and the actual name for display). Thus I will need a customRenderer to dereference the actual name
for display. Right ? Now, in the interface for ListCellRenderer, there is
a method:

What is the type of value parameter and who actually sets it ?
Thanks
G
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The type of value is determined by what you defined "myCustomModel" to be. It could be any object you wish. In your example, the renderer will be given the objects in your Map which will be an object. I usually use an array of objects for myCustomModel that I can call toString() on or some other getter that I use to to call like so:
 
Gavin Bong
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim.

If you look at the picture, I'm now able to display the strings in the combobox instead of the codes. However the selected item is now showing the code. This is due to the fact that I overrode getSelectedItem() in my custom model.
e.g.

Basically the getSelectedItem is behaving like I want it to be. However
the combobox should highlight the selected item & not display its code.
Any comments ?
Thanks
G
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is the problem with the renderer. What is the value you are setting in setText()?
I am facing a problem with Combobox renderer - even though I explicitly (programatically) set the selectedindex to -1 or selecteditem to null, combobox is displaying some value. How about you?
reply
    Bookmark Topic Watch Topic
  • New Topic