1

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 );

}

}

作成したテーブルの後にボタンを追加するにはどうすればよいですか?

前もって感謝します

4

1 に答える 1

1

(たとえば) テーブルの下に別のコンポーネントを追加する場合は、次を使用できます。

topPanel.add( button, BorderLayout.SOUTH );

そうですか?

于 2010-04-26T10:34:15.377 に答える