Bonjour,
Je suis débutant en Java et je voudrais réaliser une interface graphique,le problème que je voudrais que les boutons a partir de verre 3 ce place juste en dessous de ceux en haut
Merci.

Nom : Sans titre.png
Affichages : 71
Taille : 55,3 Ko

Voila le code que j'ai utilisé:

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
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
package exemple;
 
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.GridBagConstraints;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
 
public class exemple {
 
	private JFrame mainFrame = null;
 
	public exemple() {
        mainFrame = new JFrame("Suivi Production");
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        /* 1- Initialisation du container. */
        mainFrame.setLayout(new GridBagLayout());
 
        /* 2- Création et initialisation d'une série de composants. */
        JButton verre1Button = new JButton("Verre 1");
        JButton verre3Button = new JButton("Verre 3");
        JButton verre4Button = new JButton("Verre 4");
        JButton pet1Button = new JButton("Pet 1");
        JButton histoButton = new JButton("Historique");
        JButton impButton = new JButton("Imprimer");
        verre1Button.setPreferredSize(verre3Button.getPreferredSize());
        verre4Button.setPreferredSize(verre3Button.getPreferredSize());
        pet1Button.setPreferredSize(verre3Button.getPreferredSize());
        JLabel lab = new JLabel(new ImageIcon("src\\téléchargemen.jpg")); 
 
        /*3- Ajout de ces composants en spécifiant les contraintes de type GridBagConstraints. */
        GridBagConstraints gbc = new GridBagConstraints();
 
        gbc.gridx = gbc.gridy = 0;
        gbc.gridheight = gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.insets = new Insets(10, 10, 10, 10);
        mainFrame.add(verre1Button, gbc);
 
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.gridheight = 1; 
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.insets = new Insets(10, 10, 10, 10);
        mainFrame.add(lab, gbc);
 
        gbc.gridx = 2;
        gbc.gridy = 0;
        gbc.gridheight = gbc.gridwidth = 1;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.insets = new Insets(10, 10, 10, 10);
        mainFrame.add(histoButton, gbc);
 
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridheight = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.NONE;
        gbc.insets = new Insets(10, 10, 10, 10);
        mainFrame.add(verre3Button, gbc);
 
        gbc.gridx = 2;
        gbc.gridy = 1;
        gbc.gridheight = gbc.gridwidth = 1;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.insets = new Insets(10, 10, 10, 10);
        mainFrame.add(impButton, gbc);
 
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.NONE;
        gbc.insets = new Insets(10, 10, 10, 10);
        mainFrame.add(verre4Button, gbc);
 
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.gridheight = 1;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.NONE;
        gbc.insets = new Insets(10, 10, 10, 10);
        mainFrame.add(pet1Button, gbc);
 
        mainFrame.setMinimumSize(new Dimension(500, 500));
        mainFrame.setLocationRelativeTo(null);
    }
 
    public void setVisible(boolean b) {
        mainFrame.setVisible(b);
    }
 
	public static void main(String[] args) {
 
                exemple mp = new exemple();
                mp.setVisible(true);
 
 
	}
 
}