I would like to know how to set a JComboBox that contain integers values that I could save.
Here is the definitions of values:
public class Item
{
private String itemDesc;
private int itemType;
public static int ENTREE=0;
public static int MAIN_MEAL=1;
public static int DESSERT=2;
public static int DRINK=3;
private float price;
int[] itemTypeArray = { ENTREE, MAIN_MEAL, DESSERT, DRINK };
Object[][] data = {{itemDesc, new Integer(itemType), new Float(price)}};
.
.
.
}
Now, I want the add a JComboBox that the user will choose 1 of the items (ENTREE, MAIN_MEAL…) and then I could set the number as an Integer.
I know that JComboBox need to be something like that:
JComboBox combo = new JComboBox(itemTypeArray.values());
JOptionPane.showMessageDialog( null, combo,"Please Enter Item Type", `JOptionPane.QUESTION_MESSAGE);`
What am I doing wrong?
The constructor for JComboBox askes for
Object[]. But you cannot convert anint[]-array to anInteger[]-array. So you have to change your list toThen it is possible to construct the combobox:
But now you have the numbers in the list
(0, 1, 2, 3). So just make aString-array:Now you can construct the combobox like this:
Now you have what you want (I think).
Notice that you are using a very strange design…