Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom CellRenderer  RSS feed

 
Gavin Bong
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • 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
 
Tim Troy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • 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?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!