Bonjour Tout le monde
Je suis novice en java et j'essaie de compiler un petit programme utilisant le gestionnaire de positions :GridBagLayout .
Seulement au lieu d'avoir un rangement vertical de mes composants ces derniers se placent horizontalement

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 
 
package swing;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
 
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JPanel;
 
public class Tp1 extends JFrame  {
 
    JFrame fenetre=new JFrame();
 
    JPanel conteneur=new JPanel();
    JLabel labelauteur=new JLabel("auteur");
    JLabel labeltitre=new JLabel("titre");
    JLabel labelsexe=new JLabel("sexe");
 
    JButton boutonvalider=new JButton("valider");
    JButton boutonannuler=new JButton("annuler");
    JButton boutonmanger=new JButton("manger");
 
    public Tp1()
    {
        this.setLayout(new GridBagLayout());
        this.setContentPane(conteneur);
        this.setSize(400,400);
        GridBagConstraints gbc = new GridBagConstraints();
 
        fenetre=new JFrame("+: argument");
        fenetre.setSize(400,300);
        fenetre.setLayout(new GridBagLayout());
 
        gbc.gridx=0;
        gbc.gridy=0;
        gbc.gridwidth=gbc.gridheight=1;
          conteneur.add(boutonannuler,gbc);
 
        gbc.gridx=0;
        gbc.gridy=1;
        gbc.gridwidth=gbc.gridheight=1;
        conteneur.add(boutonvalider,gbc);
 
        gbc.gridx=0;
        gbc.gridy=2;
        gbc.gridwidth=gbc.gridheight=1;
        conteneur.add(boutonmanger,gbc);
 
                this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(300,300);
 
    }
 
    public static void main(String[] args) {
 
        Tp1 g=new Tp1();
        g.setVisible(true);
    }
}