Bonjour,

J'ai écrit une classe qui est affiche une boite de dialogue qui contient:
- un label sur la premiere ligne
- un label et une combo box (l'un à côté de l'autre) sur la 2e ligne
- un label, une combo box et jtexte field, l'un à coté de l'autre, sur la 3e ligne
- un bouton ok et un bouton cancel à la 4 ligne

mais g un pb de dimensionnement et le résultat n'est pas très beau:

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
 
import javax.swing.* ;
import java.awt.*;
 
public class Dialog extends JDialog{
 
 
 private  JPanel pnlRecoFV ;
 private  JLabel recoFVInstrumentLbl ;
 private  JLabel recommendationLbl ;
 private  JComboBox recommendationBox ; 
 private  JLabel fairValueLbl ;
 private  JComboBox fairValueBox ;
 private  JTextField fairValueText ; 
 private  JPanel pnlInstrument ;
 private  JPanel pnlReco ;
 private  JPanel pnlFV ;
 private  JButton addButton ;
 private  JButton cancelButton ;
 private  JPanel pnlButtonsRecoFV ; 
 
 
//********** Constructeur ****************
 
public Dialog() {
 
  super();
 
  pnlRecoFV = new JPanel() ;
  recoFVInstrumentLbl = new JLabel() ;
  recommendationLbl = new JLabel() ;
  recommendationBox = new JComboBox() ;
  fairValueLbl = new JLabel() ;
  fairValueBox = new JComboBox() ;
  fairValueText = new JTextField() ;
  pnlInstrument = new JPanel() ;
  pnlReco = new JPanel() ;
  pnlFV = new JPanel() ;
  addButton = new JButton("Add") ;
  cancelButton = new JButton("Cancel") ;
  pnlButtonsRecoFV = new JPanel() ;
 
 
    pnlRecoFV.setLayout(new BoxLayout(pnlRecoFV, BoxLayout.Y_AXIS));
    pnlInstrument.setLayout(new BoxLayout(pnlInstrument, BoxLayout.X_AXIS));
    pnlReco.setLayout(new BoxLayout(pnlReco, BoxLayout.X_AXIS));
    pnlFV.setLayout(new BoxLayout(pnlFV, BoxLayout.X_AXIS));
    pnlButtonsRecoFV.setLayout(new BoxLayout(pnlButtonsRecoFV, BoxLayout.X_AXIS));
 
    recoFVInstrumentLbl.setText("Instrument: ");
    recommendationLbl.setText("Recommendation :");
    fairValueLbl.setText("Fair value: ");
 
    recommendationBox.setPreferredSize(new Dimension(100, 80));
    fairValueBox.setPreferredSize(new Dimension(100, 80));
 
    pnlInstrument.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
    pnlInstrument.add(recoFVInstrumentLbl);
 
    pnlReco.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
    pnlReco.add(recommendationLbl);
    pnlReco.add(recommendationBox);
 
    pnlFV.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
    pnlButtonsRecoFV.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
    pnlFV.add(fairValueLbl);
    pnlFV.add(fairValueBox);
    pnlFV.add(fairValueText);  
    pnlButtonsRecoFV.add(addButton);
    pnlButtonsRecoFV.add(cancelButton);
 
    pnlRecoFV.add(pnlInstrument);
    pnlRecoFV.add(pnlReco);
    pnlRecoFV.add(pnlFV);
    pnlRecoFV.add(pnlButtonsRecoFV);
 
    this.add(pnlRecoFV);
    this.setVisible(true); 
 
    pack() ;
 
 }
 
//********************* main *********************
 
public static void main(String[] argv) {
	Dialog dialog = new Dialog() ;
 
 }
 
}//class
La boite de dialogue contient le panel principal "pnlRecoFV" qui contient à son tour 4 panels: pnlInstrument, pnlReco, pnlFV et pnlButtonsRecoFV dans l'ordre, du haut vers le bas.
Le layout manager que g utilisé est le BoxLayout.
donc, pnlRecoFV aligne ses panels sur l'axe Y (vertical) et tous les autres panels alignent leurs composants sur l'axe X (horizontal)

est-ce que quelqu'un peut m'aider à avoir un meilleur résultat svp?

Merci