I have a JComboBox
in Java, where I show a list of employees, result of a Query, I store it in a ResultSet and I want it to be that when it is selected, I take the ID and not the name, unlike C # , Java does not have a tool like DisplayMember
or ValueMember
that allows me to easily display a text and when selecting it to take the value, the method where I assign the resultSet to my combo is as follows:
while(rs.next())
{
fila = new Object[colNo];
for(int i=0;i<2;i++)
{
fila[i] = rs.getObject(i+1);
employeesCombo.addItem(fila[i]);
}
}
My question is, what is the easiest way to do it? Since if it shows the data, but not in the way I want, I'm new to Java, so I'm not that familiar. This is the way they are displayed, first show the ID and then the name of the employee: