I have a table with two columns – id and desc. Is it possible to show a list of desc column values to the user in a JComboBox and when the user selects an item from the list and clicks a button, I get its corresponding id value?
That is, is it possible to do something like this in Swing?
<select>
<option value="1">Hi</option>
<option value="2">Hello</option>
</select>
When the user clicks Hello, I would need 2 as the value.
Here is an example using a JComboBox. The concept is identical for a JList:
Or you could always use a JTable to store the data and just remove the first TableColumn fro the TableColumnModel so its not visible in the table.