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
|
public class Toto {
ArrayList<JComboBox> jComboBoxList = new ArrayList<JComboBox>();
JFrame jFrame = new JFrame();
JPanel jPanel = new JPanel();
public static void main(String[] args)
{
Toto toto = new Toto();
toto.init();
}
private void init()
{
jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
GridLayout gd = new GridLayout();
gd.setRows(4);
jPanel.setLayout(gd);
jFrame.setContentPane(jPanel);
//Bouton pour ajouter combo
JButton jButton = new JButton("Ajouter");
jButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
ajouterCombo();
}
});
jPanel.add(jButton);
//Ajoute 3 pour commencer
for (int i = 0; i < 3; i++)
{
ajouterCombo();
}
jFrame.pack();
jFrame.setVisible(true);
}
private void ajouterCombo()
{
JComboBox box = new JComboBox();
box.setPreferredSize(new Dimension(60,20));
jComboBoxList.add(box);
jPanel.add(box);
jFrame.pack();
}
} |
Partager