Java ComboBox Different Value to Name
问题 I have a Java combo box and a project linked to an SQLite database. If I've got an object with an associated ID and name: class Employee { public String name; public int id; } what's the best way of putting these entries into a JComboBox so that the user sees the name of the employee but I can retreive the employeeID when I do: selEmployee.getSelectedItem(); Thanks 回答1: First method: implement toString() on the Employee class, and make it return the name. Make your combo box model contain