Is it possible to have a JComboBox which holds two values for each entry it lists such as a title and an underlying numeric value for that title? (As with select boxes in HTML)
Likewise, is it possible to do the same for a JList component?
Alternatively you can use your own ADT as the combo box's value - an object that holds your numeric value and the title. example:
Code:
class OwnADT
{
public int id;
public String title;
public OwnADT(id, title)
{
this.id = id;
this.title = title;
}
public String toString()
{
return this.title;
}
}
Like that you don't have to change the renderer and can access the numeric data via a direct cast:
Code:
int id = ((OwnADT)myComboBox.getSelectedItem()).id;
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.