add JButton into frame with JTable

Posted by Edan on Stack Overflow See other posts from Stack Overflow or by Edan
Published on 2010-04-26T10:17:31Z Indexed on 2010/04/26 10:43 UTC
Read the original article Hit count: 468

Filed under:
|
|
|

hello,

I would like to know how to put a button inside a frame that contain JTable inside. (The button should not be inside a cell, but after the table ends) Here is the example code I wrote so far:

class SimpleTableExample extends JFrame

{

// Instance attributes used in this example

private JPanel topPanel;

private JTable table;

private JScrollPane scrollPane; private JButton update_Button;

// Constructor of main frame
public SimpleTableExample()
{
    // Set the frame characteristics
    setTitle("Add new item" );
    setSize(300, 200);
    setBackground( Color.gray );

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



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

    // Create some data
    String dataValues[][] = {{ "0", "Entree", "0" }};

    // Create a new table instance
    table = new JTable( dataValues, columnNames );

    ////////////////////////////

    JComboBox item_Type_Combobox = new JComboBox();
    item_Type_Combobox = new JComboBox(item_Type.values());
    TableColumn column = table.getColumnModel().getColumn(1);
    column.setCellEditor(new DefaultCellEditor(item_Type_Combobox));


    ////////////////////////////    



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

}

}

How do I add button after the table I created?

thanks in advance

© Stack Overflow or respective owner

Related posts about java

Related posts about jtable