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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Vector;
import javax.swing.*;
public class AjoutCanariPanel extends JPanel{
/* --- Attributs --- */
private Vector nbBague = new Vector();
private final String[] genre = { "Mâle", "Femelle","Non défini" };
private static final int NB_BAGUE_MAX = 999;
private JTextField stamField = new JTextField(10);
private JTextField anneeField = new JTextField(10);
private JTextField pereField = new JTextField(10);
private JTextField mereField = new JTextField(10);
private JComboBox bagueCombo;
private JComboBox sexeCombo= new JComboBox(genre);
private JLabel identifiantLabel = new JLabel("Identifiant :");
private JLabel anneeLabel = new JLabel("Année");
private JLabel stamLabel = new JLabel("Stam");
private JLabel bagueLabel = new JLabel("Bague");
private JLabel sexeLabel = new JLabel("Sexe :");
private JLabel pereLabel = new JLabel("Père :");
private JLabel mereLabel = new JLabel("Mère :");
private JPanel panelIdentifiant;
public AjoutCanariPanel(){
super();
init();
}
public void init(){
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridbag);
identifiantPanel();
c.anchor=GridBagConstraints.WEST;
/*gridbag.setConstraints(identifiantLabel,c);
add(identifiantLabel);*/
c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
gridbag.setConstraints(panelIdentifiant,c);
add(panelIdentifiant);
c.gridwidth = GridBagConstraints.RELATIVE;
gridbag.setConstraints(sexeLabel,c);
add(sexeLabel);
c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
gridbag.setConstraints(sexeCombo,c);
add(sexeCombo);
c.gridwidth = GridBagConstraints.RELATIVE; // en dessous du premier label
gridbag.setConstraints(pereLabel,c);
add(pereLabel);
c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
gridbag.setConstraints(pereField,c);
add(pereField);
c.gridwidth = GridBagConstraints.RELATIVE; // en dessous du premier label
gridbag.setConstraints(mereLabel,c);
add(mereLabel);
c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
gridbag.setConstraints(mereField,c);
add(mereField);
}
public void identifiantPanel() {
for (int i = 1; i <= NB_BAGUE_MAX; i++) {
nbBague.addElement("" + i);
}
bagueCombo = new JComboBox(nbBague);
GridBagLayout grid = new GridBagLayout();
panelIdentifiant = new JPanel(grid);
GridBagConstraints co = new GridBagConstraints();
co.fill = GridBagConstraints.HORIZONTAL;
co.gridx = 0;
co.gridy = 0;
grid.setConstraints(bagueLabel, co);
panelIdentifiant.add(bagueLabel);
co.gridx = 1;
co.gridy = 0;
grid.setConstraints(stamLabel, co);
panelIdentifiant.add(stamLabel);
co.gridx = 2;
co.gridy = 0;
grid.setConstraints(anneeLabel, co);
panelIdentifiant.add(anneeLabel);
co.gridx = 0;
co.gridy = 1;
grid.setConstraints(bagueCombo, co);
panelIdentifiant.add(bagueCombo);
co.gridx = 1;
co.gridy = 1;
grid.setConstraints(stamField, co);
panelIdentifiant.add(stamField);
co.gridx = 2;
co.gridy = 1;
grid.setConstraints(anneeField, co);
panelIdentifiant.add(anneeField);
panelIdentifiant.setBorder(
BorderFactory.createTitledBorder("Identifiant:"));
}
} |
Partager