Search uneditable combo box using rendered value

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Search uneditable combo box using rendered value

Postby jeffastorey » Wed Jan 11, 2012 8:32 am

I'm using the AutoCompletion on a combo box, and when it is uneditable, it still allows me to search, which is nice. But, it looks like it is searching on the actual element values, and not the rendered values when using a custom renderer.

So for example, if I have a combo box of a Person object, and the combo box renders the object using the person.name, the combo box might look something like
Bill
Joe
Tom

But, when trying to use search, since the objects in the combo box are actually Person objects and not strings, the search will not find them. Is there a way to use the rendered value for searching, since that is what the user will see?

Note: I have been able to make this work by overriding convertElementToString, getting the renderer from the combo, and rendering the value to determine what the rendered value is, but this is not a 100% solution, since I have to try to get the text from the list cell component by checking what kind of component it is and calling the correct method (e.g. if it's a JLabel, call ((JLabel)component).getText())

Thanks,
Jeff
jeffastorey
 
Posts: 12
Joined: Tue Nov 23, 2010 12:51 pm

Re: Search uneditable combo box using rendered value

Postby JIDE Support » Wed Jan 11, 2012 9:16 am

AutoCompletion uses a Searchable. By default a ComboBoxSearchable is created which uses item.toString() to convert the element value to String. So you can override toString on your element class to make it working. Or you can subclass ComboBoxSearchable's convertElementToString where you can provide a way to convert the element to String.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 36503
Joined: Sun Sep 14, 2003 10:49 am

Re: Search uneditable combo box using rendered value

Postby jeffastorey » Wed Jan 11, 2012 9:19 am

Thanks, I ended up creating a searchable (see my note above). It's not perfect, because it only handles when the renderer is certain types of components, but for most cases it should work.
jeffastorey
 
Posts: 12
Joined: Tue Nov 23, 2010 12:51 pm

Re: Search uneditable combo box using rendered value

Postby JIDE Support » Wed Jan 11, 2012 9:26 am

It is not a good idea to convert the value to String by retrieving the list cell renderer component as it will slow down the performance. We have no intention to deal with the renderer component in our code because convertElementToString is suppose to be a Model concept and the renderer component a View concept. We certainly don't want to mix them. Overriding convertElementToString properly is the only way I can suggest.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 36503
Joined: Sun Sep 14, 2003 10:49 am

Re: Search uneditable combo box using rendered value

Postby jeffastorey » Wed Jan 11, 2012 11:10 am

Thank you. I appreciate the input.
jeffastorey
 
Posts: 12
Joined: Tue Nov 23, 2010 12:51 pm


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 4 guests