Solved

Getting Object and Objectinformations selected in Combobox

Posted on 2006-06-26
5
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Desingning Refactoring existing code 2 31
jboss 7.1 start up error 1 60
mysql jsp example issue 32 69
ejb entity bean example 2 31
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 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