Solved

Getting Object and Objectinformations selected in Combobox

Posted on 2006-06-26
5
222 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:mfAudi
  • 3
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 16982060
YourObject o = (YourObject)cb.getSelectedItem();
0
 
LVL 92

Expert Comment

by:objects
ID: 16982113
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16982130
:-)
0
 

Author Comment

by:mfAudi
ID: 16982152
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16982208
>>Just one question: Where do you come from??

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

770 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