1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
table = new JTable();
Object[] columns = {"Id article","Libellé","Prix"};
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(columns);
table.setModel(model);
table.setRowHeight(22);
table.setBounds(10, 52, 477, 118);
contentPane.add(table);
articleID = new JTextField();
articleID.setBounds(155, 247, 121, 20);
contentPane.add(articleID);
articleID.setColumns(10);
articleLIBELLE = new JTextField();
articleLIBELLE.setBounds(155, 278, 121, 20);
contentPane.add(articleLIBELLE);
articleLIBELLE.setColumns(10);
articlePRIX = new JTextField();
articlePRIX.setText("");
articlePRIX.setBounds(155, 309, 121, 20);
contentPane.add(articlePRIX);
articlePRIX.setColumns(10);
// create JScrollPane
JScrollPane scroll = new JScrollPane(table);
scroll.setBounds(20, 60, 550, 120);
contentPane.setLayout(null);
contentPane.add(scroll);
// create an array of objects to set the row data
Object[] row = new Object[3];
JButton btnAjouterLarticleAu = new JButton("Ajouter l'article au devis");
// button add row
btnAjouterLarticleAu.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
row[0] = articleID.getText();
row[1] = articleLIBELLE.getText();
row[2] = articlePRIX.getText();
// add row to the model
model.addRow(row);
}
}); |
Partager