Bonjour, j'ai un petit problème graphique que je n'arrive pas à résoudre.
je veux placer plusieurs composant de cette façon là:


et j'ai plutôt ça!


donc voilà mon problème je ne comprend pas pourquoi certains de mes composants se coupent, et pourquoi mes boutons se décalent à droite.
Je vous laisse mon code décomposé en 4classes une principale(fenêtre) une dessinant les leds une dessinant les afficheurs 7segments et une dessinant l'afficheur hexadécimal:

mais je ne pense pas que le problème vienne des autres classes que fenêtre, car lorsque je les ai testées seul elles fonctionnaient (je les ai donc mis juste pour info)
je n'ai également pas mis la classe main permettant de le lancer, mais c'est juste une instance de fenêtre.

Donc voilà si quelqu'un peut m'aider SVP, JE GALERE DEPUIS 5 JOUR DESSUS ARG!!!
merci
cdlt le débutant

voici la classe Fenetre

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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
 
public class Fenetre extends JFrame{
    public Fenetre()
    {
        JFrame afficheurPan = new JFrame("test du gridbaglayout");
        afficheurPan.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        //on crée le composant de 16 leds
        Leds led = new Leds();
        //on crée le composant afficheur 7 segment
        Affichicheur7segments aff7seg = new Affichicheur7segments();
        //on crée l'afficheur hexadecimal
        AffHexaPan affHexa = new AffHexaPan();
        //on crée les boutons et les indicateurs on/off
        String activInter1 = "on";
        String activInter2 = "on";
        String activInter3 = "on";
        String activInter4 = "on";
        String activInter5 = "on";
        String activInter6 = "on";
        JButton inter1 = new JButton("1");
        inter1.setPreferredSize(new Dimension(41,15));
        JLabel activationInter1 = new JLabel(activInter1);
        JButton inter2 = new JButton("2");
        inter2.setPreferredSize(new Dimension(41,15));
        JLabel activationInter2 = new JLabel(activInter2);
        JButton inter3 = new JButton("3");
        inter3.setPreferredSize(new Dimension(41,15));
        JLabel activationInter3 = new JLabel(activInter3);
        JButton inter4 = new JButton("4");
        inter4.setPreferredSize(new Dimension(41,15));
        JLabel activationInter4 = new JLabel(activInter4);
        JButton inter5 = new JButton("5");
        inter5.setPreferredSize(new Dimension(41,15));
        JLabel activationInter5 = new JLabel(activInter5);
        JButton inter6 = new JButton("6");
        inter6.setPreferredSize(new Dimension(41,15));
        JLabel activationInter6 = new JLabel(activInter6);
 
        afficheurPan.setLayout(new GridBagLayout());
        //on crée les contraintes associées au GridBagLayout
        GridBagConstraints gbc = new GridBagConstraints();
 
        gbc.gridx = 0;//premiere colonne
        gbc.gridy = 0;//premiere ligne
        gbc.gridheight = 1;//une seule cellule de haut
        gbc.gridwidth = GridBagConstraints.REMAINDER;//c'est le seul element de la ligne
        gbc.weightx = 1;
        gbc.weighty = 1;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.insets = new Insets(10,15,0,0);//marge de 15px à gauche et 10px au dessus
        afficheurPan.add(led,gbc);//affichage des leds
 
        //on passe à la mise en place des interrupteurs et de leurs indicateurs
        gbc.gridy = 1;//deuxieme ligne
 
        gbc.anchor = GridBagConstraints.FIRST_LINE_START;
        gbc.insets = new Insets(1,1,1,1);
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.gridx = 0;
        afficheurPan.add(inter1,gbc);
 
        gbc.anchor = GridBagConstraints.FIRST_LINE_START;
        gbc.insets = new Insets(1,1,1,1);
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.gridx = 1;
        afficheurPan.add(inter2,gbc);
 
        gbc.anchor = GridBagConstraints.FIRST_LINE_START;
        gbc.insets = new Insets(1,1,1,1);
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.gridx = 2;
        afficheurPan.add(inter3,gbc);
 
        gbc.anchor = GridBagConstraints.FIRST_LINE_START;
        gbc.insets = new Insets(1,1,1,1);
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.gridx = 3;
        afficheurPan.add(inter4,gbc);
 
        gbc.anchor = GridBagConstraints.FIRST_LINE_START;
        gbc.insets = new Insets(1,1,1,1);
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.gridx = 4;
        afficheurPan.add(inter5,gbc);
 
        gbc.anchor = GridBagConstraints.FIRST_LINE_START;
        gbc.insets = new Insets(1,1,1,1);
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.gridx = 5;
        afficheurPan.add(inter6,gbc);
 
        gbc.gridy = 2;//troisieme ligne
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.insets = new Insets(1,1,1,1);//petite marge autour du composant
        gbc.gridheight = 1;//hauteur de une seule cellule
        gbc.gridwidth = 1;
        gbc.gridx = 0;//1ere colonne
        afficheurPan.add(activationInter1,gbc);
        gbc.gridx = 1;//2eme colonne
        afficheurPan.add(activationInter2,gbc);
        gbc.gridx = 2;//3eme colonne
        afficheurPan.add(activationInter3,gbc);
        gbc.gridx = 3;//4eme colonne
        afficheurPan.add(activationInter4,gbc);
        gbc.gridx = 4;//5eme colonne
        afficheurPan.add(activationInter5,gbc);
        gbc.gridx = 5;//6eme colonne
        afficheurPan.add(activationInter6,gbc);
 
        //mise en place des afficheurs
        gbc.gridx = 0;//1ere colonne
        gbc.gridy = 3;//4eme ligne
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.weightx = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.insets = new Insets(0,0,0,0);
        afficheurPan.add(aff7seg,gbc);
 
        gbc.gridx = 1;//2eme colonne
        gbc.gridy = 3;//4eme ligne
        gbc.gridheight = 1;
        gbc.gridwidth = 1;
        gbc.weightx = 1;
        gbc.gridwidth = GridBagConstraints.REMAINDER;//c'est le seul element de la ligne
        gbc.insets = new Insets(0,0,0,0);
        afficheurPan.add(affHexa,gbc);
 
        afficheurPan.setMinimumSize(new Dimension(620, 300));
        afficheurPan.setLocationRelativeTo(null);
        afficheurPan.setVisible(true);
    }
}
la classe Leds permettant de creer les leds (les points rouges)
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
 
 
public class Leds extends JPanel{
private static final long serialVersionUID = 1;
/***************************** VARIABLES GLOBALES DE LA CLASSE ***********************************/
		//Tableau qui sélectionnera les leds à allumer
		static Color [] color = new Color[16];
/**Constructeur de la classe LedsPan
 *
 */
/****************************************** CONSTRUCTEUR******************************************/
		public Leds(){
			setPreferredSize(new Dimension(200,60));
			for(int i=0;i<16;i++)color[i] = Color.pink;
		}
/************************************** METHODE PAINTCOMPONENT **********************************/
    @Override
	public void paintComponent(Graphics g){
		int x=10;
		int y=10;
 
		for(int i=0;i<16;i++){
 
			if((i%4) == 0){x+=25;}
			if(i!=0)x+=20;
 
			/**
                         * Dessin d'une led
                         */
			g.setColor(color[i]);
			int xl=x;
			int yl=y;
			g.fillOval(xl,yl,15,15);
		}
	}
 
 
}
voici la classe permettant de créer l'afficheur 7 segments
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
 
public class Affichicheur7segments extends JPanel{
 
private static final long serialVersionUID = 1;
/***************************** VARIABLES GLOBALES DE LA CLASSE ***********************************/
		//Tableau qui sélectionnera les afficheurs actifs (ici valeurs par défaut)
		int [] TabAff = new int [4];
		//Tableau qui sélectionnera les segments à allumer (ici valeurs par défaut)
		static Color [] color = new Color[8];
/**
 * Constructeur de la classe Aff7SegPan
 */
/****************************************** CONSTRUCTEUR******************************************/
		public Affichicheur7segments(){
			setPreferredSize(new Dimension(270,130));
			for(int i=0;i<4;i++)TabAff[i] = 1;
			for(int i=0;i<8;i++)color[i] = Color.lightGray;
		}
/************************************** METHODE PAINTCOMPONENT **********************************/
    @Override
	public void paintComponent(Graphics g)
    {
		int x=0;
		int y=0;
 
		for(int i=1;i<5;i++)
        {
			x=0+65*(i-1);
			/**
                         * Dessin du segment a
                         */
			if (TabAff[i-1]==0)g.setColor(color[0]);
			else g.setColor(Color.lightGray);
			int xa[]={53+x,48+x,18+x,13+x,18+x,48+x};
			int ya[]={5+y,0+y,0+y,5+y,10+y,10+y};
			Polygon segmenta = new Polygon(xa,ya,6);
			g.fillPolygon(segmenta);
			/**
                         * Dessin du segment b
                         */
			if (TabAff[i-1]==0)  g.setColor(color[1]);
			else g.setColor(Color.lightGray);
			int xb[]={55+x,60+x,60+x,55+x,50+x,50+x};
			int yb[]={7+y,12+y,42+y,47+y,42+y,12+y};
			Polygon segmentb = new Polygon(xb,yb,6);
			g.fillPolygon(segmentb);
			/**
                         * Dessin du segment c
                         */
			if (TabAff[i-1]==0)  g.setColor(color[2]);
			else g.setColor(Color.lightGray);
			int xc[]={55+x,60+x,60+x,55+x,50+x,50+x};
			int yc[]={52+y,57+y,87+y,92+y,87+y,57+y};
			Polygon segmentc = new Polygon(xc,yc,6);
			g.fillPolygon(segmentc);
			/**
                         * Dessin du segment d
                         */
			if (TabAff[i-1]==0)  g.setColor(color[3]);
			else g.setColor(Color.lightGray);
			int xd[]={53+x,48+x,18+x,13+x,18+x,48+x};
			int yd[]={95+y,100+y,100+y,95+y,90+y,90+y};
			Polygon segmentd = new Polygon(xd,yd,6);
			g.fillPolygon(segmentd);
			/**
                         * Dessin du segment e
                         */
			if (TabAff[i-1]==0)  g.setColor(color[4]);
			else g.setColor(Color.lightGray);
			int xe[]={12+x,17+x,17+x,12+x,7+x,7+x};
			int ye[]={52+y,57+y,87+y,92+y,87+y,57+y};
			Polygon segmente = new Polygon(xe,ye,6);
			g.fillPolygon(segmente);
			/**
                         * Dessin du segment f
                         */
			if (TabAff[i-1]==0)  g.setColor(color[5]);
			else g.setColor(Color.lightGray);
			int xf[]={12+x,17+x,17+x,12+x,7+x,7+x};
			int yf[]={7+y,12+y,42+y,47+y,42+y,12+y};
			Polygon segmentf = new Polygon(xf,yf,6);
			g.fillPolygon(segmentf);
			/**
                         * Dessin du segment g
                         */
			if (TabAff[i-1]==0)  g.setColor(color[6]);
			else g.setColor(Color.lightGray);
			int xg[]={53+x,48+x,18+x,13+x,18+x,48+x};
			int yg[]={50+y,55+y,55+y,50+y,45+y,45+y};
			Polygon segmentg = new Polygon(xg,yg,6);
			g.fillPolygon(segmentg);
			/**
                         * Dessin du point p
                         */
			if (TabAff[i-1]==0)  g.setColor(color[7]);
			else g.setColor(Color.lightGray);
			int xp=60+x;
			int yp=90+y;
			g.fillOval(xp,yp,10,10);
		}
	}
}
la classe permettant de créer l'afficheur hexadecimal
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
 
public class AffHexaPan extends JPanel{
private static final long serialVersionUID = 1;
/***************************** VARIABLES GLOBALES DE LA CLASSE ***********************************/
		//Tableau qui precisera si les afficheurs sont actifs
		boolean TabAff;
		//Tableau qui sélectionnera les segments actifs
		/**             0
                 *              --
                 *        5|__|1
                 *        4| 6|2
                 *              --
                 *              3
                 */
		//Tableau qui sélectionnera les segments à allumer
		static Color [][] color = new Color[4][7];
		int tabAff[] = new int[4];
/**
 * Constructeur de la classe AffHexaPan
 */
/****************************************** CONSTRUCTEUR******************************************/
		public AffHexaPan()
        {
			setPreferredSize(new Dimension(100,130));
			setLocation(20,20);
			TabAff = false;
			for(int j=0;j<4;j++)
            {
				for(int i=0;i<7;i++)color[j][i] = Color.lightGray;
			}
		}
/************************************** METHODE PAINTCOMPONENT **********************************/
	public void paintComponent(Graphics g)
    {
		int xd = 0;
		int xpl = 30;
		int ypl = 30;
		int x = 0;
		int y = 0;
		for(int i=1;i<5;i++){
			xd=50*(i-1);
			/**
                         * Dessin des 5 points du haut a gauche
                         */
			if (TabAff) g.setColor(color[i-1][5]);
			else g.setColor(Color.lightGray);
			for(int j=1;j<6;j++){
				x = 0 + xd + xpl;
				y = 8*(j-1) + ypl;
				/**
                                 * Dessin d un point
                                 */
				int xp=x;
				int yp=y;
				g.fillOval(xp,yp,6,6);
			}
			/**
                         * Dessin des 5 points du haut a droite
                         */
			if (TabAff) g.setColor(color[i-1][1]);
			else g.setColor(Color.lightGray);
			for(int j=1;j<6;j++){
				x = 8*4 + xd + xpl;
				y = 8*(j-1) + ypl;
				/**
                                 * Dessin d un point
                                 */
				int xp=x;
				int yp=y;
				g.fillOval(xp,yp,6,6);
			}
			/**
                         * Dessin des 5 points du bas a gauche
                         */
			if (TabAff) g.setColor(color[i-1][4]);
			else g.setColor(Color.lightGray);
			for(int j=1;j<6;j++){
				x = 0 + xd + xpl;
				y = 8*4+8*(j-1) + ypl;
				/**
                                 * Dessin d un point
                                 */
				int xp=x;
				int yp=y;
				g.fillOval(xp,yp,6,6);
			}
			/**
                         * Dessin des 5 points du bas a droite
                         */
			if (TabAff) g.setColor(color[i-1][2]);
			else g.setColor(Color.lightGray);
			for(int j=1;j<6;j++){
				x = 8*4 + xd + xpl;
				y = 8*4+8*(j-1) + ypl;
				/**
                                 * Dessin d un point
                                 */
				int xp=x;
				int yp=y;
				g.fillOval(xp,yp,6,6);
			}
			/**
                         * Dessin des 5 points du bas
                         */
			if (TabAff) g.setColor(color[i-1][3]);
			else g.setColor(Color.lightGray);
			for(int j=1;j<6;j++){
				x = 8*(j-1) + xd + xpl;
				y = 8*4*2 + ypl;
				/**
                                 * Dessin d un point
                                 */
				int xp=x;
				int yp=y;
				g.fillOval(xp,yp,6,6);
			}
			/**
                         * Dessin des 5 points du milieu
                         */
			if (TabAff) g.setColor(color[i-1][6]);
			else g.setColor(Color.lightGray);
			for(int j=1;j<6;j++){
				x = 8*(j-1) + xd + xpl;
				y = 8*4 + ypl;
				/**
                                 * Dessin d un point
                                 */
				int xp=x;
				int yp=y;
				g.fillOval(xp,yp,6,6);
			}
			/**
                         * Dessin des 5 points du haut
                         */
			if (TabAff) g.setColor(color[i-1][0]);
			else g.setColor(Color.lightGray);
			for(int j=1;j<6;j++){
				x = 8*(j-1) + xd + xpl;
				y = 0 + ypl;
				/**
                                 * Dessin d un point
                                 */
				int xp=x;
				int yp=y;
				g.fillOval(xp,yp,6,6);
			}
			/**
                         * On redessine les bords
                         */
			if(TabAff){
				if(color[i-1][0] == Color.red){
					g.setColor(color[i-1][0]);
					for(int j=1;j<6;j++){
						x = 8*(j-1) + xd + xpl;
						y = 0 + ypl;
						int xp=x;
						int yp=y;
						g.fillOval(xp,yp,6,6);
					}
				}
				if(color[i-1][1] == Color.red){
					g.setColor(color[i-1][1]);
					for(int j=1;j<6;j++){
						x = 8*4 + xd + xpl;
						y = 8*(j-1) + ypl;
						int xp=x;
						int yp=y;
						g.fillOval(xp,yp,6,6);
					}
				}
				if(color[i-1][2] == Color.red){
					g.setColor(color[i-1][2]);
					for(int j=1;j<6;j++){
						x = 8*4 + xd + xpl;
						y = 8*4+8*(j-1) + ypl;
						int xp=x;
						int yp=y;
						g.fillOval(xp,yp,6,6);
					}
				}
				if(color[i-1][3] == Color.red){
					g.setColor(color[i-1][3]);
					for(int j=1;j<6;j++){
						x = 8*(j-1) + xd + xpl;
						y = 8*4*2 + ypl;
						int xp=x;
						int yp=y;
						g.fillOval(xp,yp,6,6);
					}
				}
				if(color[i-1][4] == Color.red){
					g.setColor(color[i-1][4]);
					for(int j=1;j<6;j++){
						x = 0 + xd + xpl;
						y = 8*4+8*(j-1) + ypl;
						int xp=x;
						int yp=y;
						g.fillOval(xp,yp,6,6);
					}
				}
				if(color[i-1][5] == Color.red){
					g.setColor(color[i-1][5]);
					for(int j=1;j<6;j++){
						x = 0 + xd + xpl;
						y = 8*(j-1) + ypl;
						int xp=x;
						int yp=y;
						g.fillOval(xp,yp,6,6);
					}
				}
				if(color[i-1][6] == Color.red){
					g.setColor(color[i-1][6]);
					for(int j=1;j<6;j++){
						x = 8*(j-1) + xd + xpl;
						y = 8*4 + ypl;
						int xp=x;
						int yp=y;
						g.fillOval(xp,yp,6,6);
					}
				}
			}
		}
	}
}
voilà, en espérant que vous pourrez m'aider, je suis à l'écoute de toutes les idées!! même si il faut tout refaire.