繁体   English   中英

使用JTable将JButton添加到框架中

[英]add JButton into frame with JTable

我想知道如何在内部包含JTable的框架内放置按钮。 (按钮不应在单元格内部,而应在表结束之后)这是我到目前为止编写的示例代码:

类SimpleTableExample扩展JFrame

{

//本示例中使用的实例属性

私有JPanel topPanel;

私有JTable表;

私有JScrollPane scrollPane; 私人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 );

}

}

创建表格后如何添加按钮?

提前致谢

如果要在下面添加另一个组件(例如),可以使用该表:

topPanel.add( button, BorderLayout.SOUTH );

你是这个意思吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM