Getting Object and Objectinformations selected in Combobox

Hello there,

once again a problem with java! I´ve got an ComboBox which is filled with objects (Object type is my own)! I can select them but can´t get the objectinformations. Can anybody show me how to handle this??

THX

mfAudi
mfAudiAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
YourObject o = (YourObject)cb.getSelectedItem();
0
 
objectsCommented:
what information would you like exactly?

yopu can use a renderer to hadle how your object is displayed

You can cast (as shgown above), and use instanceof to check the type of the value

eg.

Object selected = combo.getSelectedItem();
if (selected instanceof MyBean)
{
   MyBean bean = (MyBean) selected;
   String property = bean.getProperty();
  // ...
}

where MyBean is obne of your classes that you are stoing in the combo


you'll find lots of goo info on usoing combos here:

http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
0
 
CEHJCommented:
:-)
0
 
mfAudiAuthor Commented:
CEHJ

THX for your help! Somtimes my brain is some kind of blocked! My thougths are just to complicated!

Just one question: Where do you come from??

0
 
CEHJCommented:
>>Just one question: Where do you come from??

Originally from Manchester UK, but living in London and Somerset
0
All Courses

From novice to tech pro — start learning today.