Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting Object and Objectinformations selected in Combobox

Posted on 2006-06-26
5
Medium Priority
?
228 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 375 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

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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:
Suggested Courses

877 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