Link to home
Start Free TrialLog in
Avatar of msouphy
msouphy

asked on

Setting and retrieving hidden value from JComboBox

hey there,

i was wondering, can I set a hidden value on an item in a JComboBox (like an ID or so) so that when an item is selected, the hidden value is returned instead of the item itself.

example:

i get ID, name and first name out of a DB

in a loop, i do a box.additem("name" + " " + first_name);
but i want to set the corresponding ID with that item, somewhere hidden...

like in html it would be <option value="id">name + first_name</option>

Can anyone help, thank you !
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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
and by extension, to get the value of your hidden field

SecretEntry se = (SecretEntry)comboBox.getSelectedItem();
System.out.println(se.getHiddenField());