Salut !


Je ne m'en sors définitevement pas avec le GridBagLayout...

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
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setLayout(new GridBagLayout());
			GridBagConstraints gbc = new GridBagConstraints();
			gbc.fill = GridBagConstraints.NONE;
			jPanel1.setPreferredSize(new Dimension(300, 210));
			jPanel1.setBackground(Color.green);
			gbc.anchor=GridBagConstraints.PAGE_START;
			gbc.anchor=GridBagConstraints.LINE_START;
			gbc.gridx = 0; gbc.gridy = 0;
			gbc.gridwidth = 1; gbc.gridheight = 1;
			gbc.weightx = 0; gbc.weighty = 0;
			jtf1.setPreferredSize(new Dimension(100,20));
			jPanel1.add(jtf1,gbc);
			gbc.gridx = 0; gbc.gridy = 1;
			gbc.gridwidth = 1; gbc.gridheight = 1;
			gbc.weightx = 0; gbc.weighty = 0;
			jtf2.setPreferredSize(new Dimension(100,20));
			jPanel1.add(jtf2,gbc);
			gbc.gridx = 0; gbc.gridy = 2;
			gbc.gridwidth = 1; gbc.gridheight = 1;
			gbc.weightx = 0; gbc.weighty = 0;
			jtf3.setPreferredSize(new Dimension(100,20));
			jPanel1.add(jtf3,gbc);
			gbc.gridx = 1; gbc.gridy = 0;
			gbc.gridwidth = 1; gbc.gridheight = 1;
			gbc.weightx = 0; gbc.weighty = 0;
			jlbl1.setText("Total");
			jPanel1.add(jlbl1,gbc);
			gbc.gridx = 1; gbc.gridy = 1;
			gbc.gridwidth = 1; gbc.gridheight = 1;
			gbc.weightx = 0; gbc.weighty = 0;
			jlbl2.setText("Mise");
			jPanel1.add(jlbl2,gbc);
			gbc.gridx = 1; gbc.gridy = 2;
			gbc.gridwidth = 1; gbc.gridheight = 1;
			gbc.weightx = 0; gbc.weighty = 0;
			jlbl3.setText("Gain");
			jPanel1.add(jlbl3,gbc);			
		}
		return jPanel1;
	}
Tel que c'est là, mes 6 composants sont centrés au milieu de mon panel. Comment faire pour qu'ils se situent en haut à gauche ?

Merci !