Bonjour,

J'ai créer un formulaire avec deux champs et un boutons sauf que j'ai deux problèmes:
- Mon bouton prend toute la largeur de mon panel alors que je souhaiterais qu'il soit centrer et qu'il prenne une taille défini.
- Mes champs textes prennent toute la largeur restante alors que je souhaiterai qu'il ne s'arrête pas au bord de la JFrame mais avant en définissant une taille.

Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
public class Formation extends JFrame {
	/**
         * serialVersionUID
         */
	private static final long serialVersionUID = 1L;
	private Box boxDefinition;
	private Box boxDefinitionLabel;
	private Box boxDefinitionText;
	private JButton boutonCreer;
	private JLabel labelNomFormation;
	private JLabel labelDureeTypeSeance;
	private JTextField txtNomFormation;
	private JTextField txtDureeTypeSeance;
	private JPanel panPrincipal;
	private JPanel panFormation;
	public Formation(){
        this.setTitle("Caractéristique de la formation");
        this.setSize(500, 500);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
 
        boxDefinition = Box.createHorizontalBox();
        // LABEL
        boxDefinitionLabel = Box.createVerticalBox();
        labelNomFormation = new JLabel("* Nom de la Formation :");
        labelNomFormation.setFont(new Font(null, Font.PLAIN, 14));
        boxDefinitionLabel.add(labelNomFormation);
        labelDureeTypeSeance = new JLabel("* Durée type d'une séance :");
        labelDureeTypeSeance.setFont(new Font(null, Font.PLAIN, 14));
 
        boxDefinitionLabel.add(labelDureeTypeSeance);
 
        boxDefinitionLabel.setPreferredSize(new Dimension(200, boxDefinitionLabel.getPreferredSize().height));
        boxDefinition.add(boxDefinitionLabel);
 
        // TEXT
        boxDefinitionText = Box.createVerticalBox();
		txtNomFormation  = new JTextField();
		txtDureeTypeSeance  = new JTextField();
		boxDefinitionText.add(txtNomFormation);
		boxDefinitionText.add(txtDureeTypeSeance);
 
		boxDefinitionText.setPreferredSize(new Dimension(100, boxDefinitionText.getPreferredSize().height));
		boxDefinition.add(boxDefinitionText);
 
		boutonCreer = new JButton("Créer la formation");
		boutonCreer.setPreferredSize(new Dimension(30, 30));
		panFormation = new JPanel(new BorderLayout());
		panFormation.add(boxDefinition, BorderLayout.NORTH);
		panFormation.add(boutonCreer, BorderLayout.CENTER);		
 
		panPrincipal = new JPanel(new BorderLayout());
        panPrincipal.add(panFormation, BorderLayout.NORTH);
        this.add(panPrincipal);
Merci de votre aide