rashmind2003
asked on
Editable jcombobox with typeahead/autocompletion feature as a cell editor for jtable
How to implement an editable Jcombobox ** with typeahead or autocompletion feature** as a cell editor for a Jtable column?
Im trying to follow this example:
http://www.orbital-computer.de/JComboBox/
Problem: My jcombobox takes a list of Objects and the selected item is being returned as an object which I later cast into
myfirm object. This works fine. But if I make Jcombobox editable, it returns the seleted object as a string rather than an
object. So when I try to cast this string into myfirm object I get a class cast exception.
How to make an editable jcombobox return an object instead of a string?
Any guidelines for implementing an editable jcombobox(with autocompletion feature) as a cell editor for a jtable?
Thanks in advance
Im trying to follow this example:
http://www.orbital-computer.de/JComboBox/
Problem: My jcombobox takes a list of Objects and the selected item is being returned as an object which I later cast into
myfirm object. This works fine. But if I make Jcombobox editable, it returns the seleted object as a string rather than an
object. So when I try to cast this string into myfirm object I get a class cast exception.
How to make an editable jcombobox return an object instead of a string?
Any guidelines for implementing an editable jcombobox(with autocompletion feature) as a cell editor for a jtable?
Thanks in advance
Meaning if you have:
String s = ( String ) comboBox.getSelectedItem () ;
Replace it with:
Object o = comboBox.getSelectedItem () ;
String s = ( o != null ) ? o.toString () : "" ;
String s = ( String ) comboBox.getSelectedItem () ;
Replace it with:
Object o = comboBox.getSelectedItem () ;
String s = ( o != null ) ? o.toString () : "" ;
ASKER
Thanks for your respone.
I want to do exactly the opposite. I do not want a string. i want an object.
Im doing Firm f = (firm) combobox.getseleteditem( )
When i seteditable(true) for combbox it returns a string instead of an object.
So I want combobox to return an object not a string.
I want to do exactly the opposite. I do not want a string. i want an object.
Im doing Firm f = (firm) combobox.getseleteditem( )
When i seteditable(true) for combbox it returns a string instead of an object.
So I want combobox to return an object not a string.
A String is an object, in effect. You can always do:
Object o = <whatever string> ;
However, if it is a String, you cannot convert it to MyFirm directly. What kind of String does it return? Meaning can you try to print it out and see what its contents are and if it is possible to create a MyFirm object from it?
Object o = <whatever string> ;
However, if it is a String, you cannot convert it to MyFirm directly. What kind of String does it return? Meaning can you try to print it out and see what its contents are and if it is possible to create a MyFirm object from it?
ASKER
Yes I can not conver a string into my object directly. So I want combobox to return an object instead of a string. If seteditable(false) my combobox does return an object and things are fine. But setting editable true makes it return a string
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
How about using toString () instead of casting? It will save you from the ClassCastException. Just make sure the object is not null before calling toString ().
- Mayank.