Is it possible to define values ββother than the actual contents in a JComboBox?
In HTML, it looks like this:
<select> <option value="value1">Content1</option> <option value="value2">Content2</option> <option value="value3">Content3</option> </select>
Here you can get a short value, no matter how long its contents.
In Java, I only know the following solution:
// Creating new JComboBox with predefined values String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" }; private JComboBox combo = new JComboBox(petStrings); // Retrieving selected value System.out.println(combo.getSelectedItem());
But here I would only get "Cat", "Dog", etc.
The problem is that I want to load all client names from the database into JComboBox, and then get the identifier from the selected client. It should look like this:
<select> <option value="104">Peter Smith</option> <option value="121">Jake Moore</option> <option value="143">Adam Leonard</option> </select>
source share