Bonjour,
J'essaye de séparer deux textes en une box avec "glue" mais je n'y arrive pas. Je ne vois pas ce qui cloche. En pièce jointe j'ai mis le résultat obtenu.
Merci pour votre aide.
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 public class Fenetre { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame my_frame = new JFrame ("Hello World") ; my_frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ; JLabel my_label = new JLabel ("centre") ; JLabel my_label2 = new JLabel ("haut1") ; JLabel my_label3 = new JLabel ("haut2") ; JLabel my_label4 = new JLabel ("dessous") ; Box bar=Box.createHorizontalBox(); bar.add(my_label2); //ici j'ajoute Glue pour les séparer bar.add(Box.createHorizontalGlue()); bar.add(my_label3); Box bar2=Box.createHorizontalBox(); bar2.add(my_label); Box bar3=Box.createHorizontalBox(); bar3.add(my_label4); Box bar4=Box.createVerticalBox(); bar4.add(bar); bar4.add(Box.createVerticalGlue()); bar4.add(bar2); bar4.add(bar3); my_frame.setPreferredSize(new Dimension(600,400)); my_frame.add(bar4); System.out.println (my_frame.getContentPane ().getLayout () instanceof java.awt.BorderLayout) ; System.out.println (my_frame.getLayout () instanceof java.awt.BorderLayout) ; my_frame.setLayout (new java.awt.FlowLayout ()) ; System.out.println (my_frame.getContentPane ().getLayout () instanceof java.awt.BorderLayout) ; System.out.println (my_frame.getLayout () instanceof java.awt.BorderLayout) ; my_frame.setLocationRelativeTo (null); my_frame.pack (); my_frame.setVisible (true); } }
Partager