Link to home
Start Free TrialLog in
Avatar of arru_in
arru_in

asked on

JComboBox internal value ?

I've a JComboBox, which gets populated from the database with  (say)
employee names. When the user selects a employee, i need to get the employee code of that person.

         Since, employee name is not unique, i can't get the employee
code from the employee name selected.

Now, consider the  following html code

<select>
<option value="E00001">ARRU</option>
<option value="EmpCode">Employee Name</option>
</select>

There can be some internal representation for each value. Is the
same kind of thing possible in JComboBox ?

Thanks in Advance
Arru_in
 
Avatar of arru_in
arru_in

ASKER

If ur confused with the question, just see the
html code alone & say where same kind of
thing is possible in JComboBox.

Thanks
Arru_in
String[] myStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };

//Create the combo box, select item at index 4.
//Indices start at 0, so 4 specifies the pig.
JComboBox myList = new JComboBox(myStrings);
muList.setSelectedIndex(4);
myList.addActionListener(this);
ASKER CERTIFIED SOLUTION
Avatar of karlika
karlika

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CEHJ
And rendering?
Avatar of arru_in

ASKER

Thanks, everyone for responding..

thanassis, i've have actually used array only. but
i thought there must be a better way (or simple way)
to do it.

 I was expecting a one line answer (any method )
which could serve my purpose. Any how it works.

thanks everyone...
So if you add

new Employee("Joe Doe", "0001")

what does it say in the combo?
JComboBox uses the toString() so, in my example combined with CEHJs data it should say "Joe Doe" in the JComboBox

Marko
OK ;-)