Bonjour,
Je cherche a construire une fenetre de ce type:
...._______________________________________________
...|.............................................................................................................|
...|................................................"Nord".................................................|
...|_______________________________________________|
...|.....................|.......................................................................................|
...|.....................|.......................................................................................|
...|.....................|.......................................................................................|
...|....."West"....|........................."Center"...............................................|
...|.....................|.......................................................................................|
...|.....................|.......................................................................................|
...|.....................|.......................................................................................|
...|.....................|.......................................................................................|
...|.....................|_____________________________________ |
...|_________|____________"South"____________________|
Qui ressemble a un borderLayout mais pas exactement. Je l'ai decoupe de la maniere suivante en grille (13*5) pour conserver les rapports de taille:
...._______________________________________________
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
...|_________|_________|_________|_________|_________|
J'ai donc ecrit le code suivant:
[ce code est directement executable dans un fichier Test.java, si vous voulez voir ce que ca donne..]
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 import javax.swing.*; import java.awt.*; public class Test{ public static void main(String[] args) { JFrame frame = new JFrame(); GridBagLayout gb = new GridBagLayout(); JPanel contentPane = new JPanel(gb); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill= GridBagConstraints.BOTH; JPanel north = new JPanel(); north.setBackground(Color.BLUE); north.add(new JLabel("north")); gbc.weightx = 1; gbc.weighty = 1; gbc.gridx= 1; gbc.gridy = 1; gbc.gridwidth = 5; gbc.gridheight = 3; contentPane.add(north, gbc); JPanel west = new JPanel(); west.setBackground(Color.GREEN); west.add(new JLabel("west")); gbc.gridx= 1; gbc.gridy = 4; gbc.gridwidth = 1; gbc.gridheight = 10; contentPane.add(west, gbc); JPanel center = new JPanel(); center.setBackground(Color.RED); center.add(new JLabel("center")); gbc.gridx= 2; gbc.gridy = 4; gbc.gridwidth = 4; gbc.gridheight = 9; contentPane.add(center, gbc); JPanel south = new JPanel(); south.setBackground(Color.GRAY); south.add(new JLabel("south")); gbc.gridx= 2; gbc.gridy = 13; gbc.gridwidth = 4; gbc.gridheight = 1; contentPane.add(south, gbc); frame.setContentPane(contentPane); frame.setSize(300,400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); } }
Mais je n'obtiens pas le rapport de taille que je desirais. En effet, le centre a la meme hauteur que le sud, et il semble que cette taille depend du contenu des panels. Comment faire pour forcer cette disposition?
calypso
Partager