how to show integer values in JComboBox?

Posted by Edan on Stack Overflow See other posts from Stack Overflow or by Edan
Published on 2010-05-01T08:14:34Z Indexed on 2010/05/01 8:27 UTC
Read the original article Hit count: 337

Filed under:
|

Hello,

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?

© Stack Overflow or respective owner

Related posts about jcombobox

Related posts about java