gingermeatboy
asked on
Swing combobox question
how can you get an int value from a combo box?
I tried this:
final JComboBox ansBox= new JComboBox();
// populate the combo box
for (int i=1; i<=10; i++) {
ansBox.addItem(""+i);
}
ansBox.setSelectedIndex(0) ;
then when trying to get the value back out I did:
int number = ((Integer) ansBox.getSelectedItem()). intValue() ;
.....
but it complains, how do you do it properly?!
cheers
I tried this:
final JComboBox ansBox= new JComboBox();
// populate the combo box
for (int i=1; i<=10; i++) {
ansBox.addItem(""+i);
}
ansBox.setSelectedIndex(0)
then when trying to get the value back out I did:
int number = ((Integer) ansBox.getSelectedItem()).
.....
but it complains, how do you do it properly?!
cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks! :o)
You are welcome.
ASKER
int number = (ansBox.getSelectedIndex()
but is there a better way?