JCombobox containing enum values inside a table

Posted by Edan on Stack Overflow See other posts from Stack Overflow or by Edan
Published on 2010-04-25T12:57:13Z Indexed on 2010/04/25 13:03 UTC
Read the original article Hit count: 302

Filed under:

Hello,

I have a class containing Enum with values. (names) In other class I would like to enter inside a table a cell type of JCombobox that will use these enums values. my problem is to combain between string values and the enum. for example the enum class:

enum item_Type {entree, main_Meal, Dessert, Drink}

for example the table class: setTitle("Add new item" ); setSize(300, 80); setBackground( Color.gray );

    // Create a panel to hold all other components
    topPanel = new JPanel();
    topPanel.setLayout( new BorderLayout() );
    getContentPane().add( topPanel );

    //new JComboBox(item_Type.values());
    JComboBox aaa = new JComboBox();
    aaa = new JComboBox(item_Type.values());
    TableColumn sportColumn = table.getColumnModel().getColumn(2);

    // Create columns names
    String columnNames[] = {"Item Description", "Item Type", "Item Price"};

    // Create some data
    String dataValues[][] = {{ "0", aaa, "0" }};
    // Create a new table instance
    table = new JTable( dataValues, columnNames );

    // Add the table to a scrolling pane
    scrollPane = new JScrollPane( table );
    topPanel.add( scrollPane, BorderLayout.CENTER );

I know that at the dataValues array I cant use aaa (the enum jcombobox). How can I do that?

thanks in advance.

© Stack Overflow or respective owner

Related posts about java