2010-04-26 4 views
1

Je voudrais savoir comment mettre un bouton à l'intérieur d'un cadre qui contient JTable à l'intérieur. (Le bouton ne doit pas être à l'intérieur d'une cellule, mais après la table se termine) Voici le code exemple je l'ai écrit jusqu'à présent:ajouter JButton dans le cadre avec JTable

SimpleTableExample classe extends JFrame

{

// Attributs d'instance utilisés dans cet exemple

private JPanel topPanel;

table JTable privée;

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

} 

}

Comment puis-je ajouter le bouton après la table que j'ai créé?

merci à l'avance

Répondre

1

Si vous voulez ajouter un autre composant ci-dessous (par exemple) la table que vous pouvez utiliser:

topPanel.add(button, BorderLayout.SOUTH); 

Est-ce que vous voulez dire?