[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Editable jcombobox with typeahead/autocompletion feature as a cell editor for jtable

Posted on 2006-04-28
8
Medium Priority
?
874 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:rashmind2003
  • 4
  • 2
6 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 16562146
>> So when I try to cast this string into myfirm object I get a class cast exception

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.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16562320
Meaning if you have:

String s = ( String ) comboBox.getSelectedItem () ;

Replace it with:

Object o = comboBox.getSelectedItem () ;
String s = ( o != null ) ? o.toString () : "" ;
0
 

Author Comment

by:rashmind2003
ID: 16562441
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 16562550
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?
0
 

Author Comment

by:rashmind2003
ID: 16562667
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
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 2000 total points
ID: 16563388
Well perhaps that is because when you make it editable, it allows you to type and it cannot allow you to type a MyFirm :) it can only allow you to type a String so the return-type becomes String. Did you check what String it is returning (what is the value of the String)? What does the MyFirm class look like?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month19 days, 4 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question