Salut à tous!
Alors voila j'explique mon problème :
J'ai une fenêtre (frame) avec deux panels dedans.
Le premier panel que j'utilise, je l'ai mis dans la zone CENTER. Ce premier panel est une zone de dessin. Celui ci ne pose aucun problème.
Le deuxième panel que j'utilise est situé dans la zone EAST.
Dans ce panel j'utilise plusieurs composants swings (JScrollpane, JTextField, JLabel etc...). La plupart doivent s'afficher les uns en dessous des autres mais certains il faudrait que je les affiche côte à côte.
Jusque là j'avais fait comme ceci pour essayer de les afficher (mais ils s'affichent tous les uns en dessous des autres) :
Je sais que le layout que j'utilise : BoxLayout.Y_AXIS n'est pas le plus approprié pour ce que je veux faire mais je n'ai rien trouvé d'autre comme solution pour le moment...
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 public class Fenetre { private JLabel jLabelTitre; private JLabel jLabelBlocsDispo; private JLabel jLabelChangeAxe; private JLabel jLabelAxeVertical; privateJLabel jLabelAxeHorizontal; private JLabel jLabelRecherche; private JLabel jLabelLimInf; private JLabel jLabelLimSup; private JTextField jTextFieldLimInf; private JTextField jTextFieldLimSup; private JFrame frame; private JList list; private JScrollPane scrollPane; private JScrollPane jScrollPanePanel; private JComboBox jComboBoxAxeVertical; private JComboBox jComboBoxAxeHorizontal; private JPanel jPanelNorth; public Fenetre (Component component) { this.frame = new JFrame(frameName); // Création des Panels : this.jPanelNorth = new JPanel(); BoxLayout BL = new BoxLayout (jPanelNorth, BoxLayout.Y_AXIS); this.jPanelNorth.setLayout(null); // Création des labels : this.jLabelTitre = new JLabel(); this.jLabelTitre.setText("Paramètres de visualisation :"); this.jLabelTitre.setAlignmentX(Component.CENTER_ALIGNMENT); this.jLabelBlocsDispo = new JLabel(); this.jLabelBlocsDispo.setText("Blocs disponibles :"); this.jLabelBlocsDispo.setAlignmentX(Component.CENTER_ALIGNMENT); this.jLabelChangeAxe = new JLabel(); this.jLabelChangeAxe.setText("Changer les axes du repères :"); this.jLabelChangeAxe.setAlignmentX(Component.CENTER_ALIGNMENT); this.jLabelAxeVertical = new JLabel(); this.jLabelAxeVertical.setText("Axe vertical :"); this.jLabelAxeVertical.setAlignmentX(Component.CENTER_ALIGNMENT); this.jLabelAxeHorizontal = new JLabel(); this.jLabelAxeHorizontal.setText("Axe horizontal :"); this.jLabelAxeHorizontal.setAlignmentX(Component.CENTER_ALIGNMENT); this.jLabelRecherche = new JLabel(); this.jLabelRecherche.setText("Recherche :"); this.jLabelRecherche.setAlignmentX(Component.CENTER_ALIGNMENT); this.jLabelLimInf = new JLabel(); this.jLabelLimInf.setText("Limite inf :"); this.jLabelLimInf.setAlignmentX(Component.CENTER_ALIGNMENT); this.jLabelLimSup = new JLabel(); this.jLabelLimSup.setText("Limite sup :"); this.jLabelLimSup.setAlignmentX(Component.CENTER_ALIGNMENT); this.jTextFieldLimInf = new JTextField(); this.jTextFieldLimInf.setMaximumSize(new Dimension(50,15)); this.jTextFieldLimInf.setAlignmentX(Component.CENTER_ALIGNMENT); this.jTextFieldLimSup = new JTextField(); this.jTextFieldLimSup.setMaximumSize(new Dimension(120,15)); this.jTextFieldLimSup.setAlignmentX(Component.CENTER_ALIGNMENT); // Liste contenant les blocs à insérer ou supprimer : // (liste avec "ascenseur" --> utilisation de scrollPane) this.list = new JList(); try { File f = new File (nomDossier); if (f.isDirectory()) { String[] tab = f.list(); Vector vecteurNomFichier = new Vector(); for (int i=0; i<tab.length; i++) { File f2 = new File (nomDossier+tab[i]); if (f2.isFile()) vecteurNomFichier.addElement (tab[i]); } list = new JList(vecteurNomFichier); } else list = new JList(); list.setSelectionMode (javax.swing.ListSelectionModel.SINGLE_SELECTION); } catch (Exception e) { System.out.println("Exception"); e.printStackTrace(); } this.scrollPane = new JScrollPane (this.list); this.scrollPane.setVisible(true); this.scrollPane.setAlignmentX(Component.CENTER_ALIGNMENT); // Création des ComboBox : this.jComboBoxAxeVertical = new JComboBox(); this.jComboBoxAxeVertical.setMaximumSize(new Dimension(150, 15)); this.jComboBoxAxeHorizontal = new JComboBox(); this.jComboBoxAxeHorizontal.setMaximumSize(new Dimension(150, 15)); // Création des boutons : this.jButtonAjouter = new JButton(); this.jButtonAjouter.setText("Ajouter"); this.jButtonAjouter.setVisible(true); this.jButtonAjouter.setMaximumSize(new Dimension(150, 15)); this.jButtonAjouter.setAlignmentX(Component.CENTER_ALIGNMENT); this.jButtonAjouter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { // traitement } }); this.jButtonEnlever = new JButton(); this.jButtonEnlever.setText("Enlever"); this.jButtonEnlever.setVisible(true); this.jButtonEnlever.setAlignmentX(Component.CENTER_ALIGNMENT); this.jButtonEnlever.setMaximumSize(new Dimension(150, 15)); this.jButtonEnlever.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { // traitement } }); // Ces composants doivent s'afficher les uns au dessous des autres : // Ajout des composants au panel this.jPanelNorth.add(this.jLabelTitre); this.jPanelNorth.add(Box.createVerticalStrut(15)); this.jPanelNorth.add(this.jLabelBlocsDispo); this.jPanelNorth.add(Box.createVerticalStrut(10)); this.jPanelNorth.add(this.scrollPane); this.jPanelNorth.add(Box.createVerticalStrut(10)); // Ces deux composants doivent s'afficher cote à cote this.jPanelNorth.add(this.jButtonAjouter); this.jPanelNorth.add(Box.createVerticalStrut(10)); this.jPanelNorth.add(this.jButtonEnlever); // Ces composants doivent s'afficher les uns au dessous des autres : this.jPanelNorth.add(Box.createVerticalStrut(15)); this.jPanelNorth.add(this.jLabelChangeAxe); this.jPanelNorth.add(Box.createVerticalStrut(10)); this.jPanelNorth.add(this.jLabelAxeVertical); this.jPanelNorth.add(Box.createVerticalStrut(10)); this.jPanelNorth.add(this.jComboBoxAxeVertical); this.jPanelNorth.add(Box.createVerticalStrut(10)); this.jPanelNorth.add(this.jLabelAxeHorizontal); this.jPanelNorth.add(Box.createVerticalStrut(10)); this.jPanelNorth.add(this.jComboBoxAxeHorizontal); this.jPanelNorth.add(Box.createVerticalStrut(15)); this.jPanelNorth.add(this.jLabelRecherche); this.jPanelNorth.add(Box.createVerticalStrut(10)); this.jPanelNorth.add(this.jLabelAxeVertical2); this.jPanelNorth.add(Box.createVerticalStrut(10)); // Les deux composants suivants doivent s'afficher cote à cote this.jPanelNorth.add(this.jLabelLimInf); this.jPanelNorth.add(this.jTextFieldLimInf); this.jPanelNorth.add(Box.createVerticalStrut(10)); // Les deux composants suivants doivent s'afficher cote a cote this.jPanelNorth.add(this.jLabelLimSup); this.jPanelNorth.add(this.jTextFieldLimSup); this.jPanelNorth.add(Box.createVerticalStrut(10)); // On met le Panel dans un scrollPane pour rajouter // automatiquement des barres de défilement si nécessaire this.scrollPanePanel = new JScrollPane (this.jPanelNorth); this.scrollPanePanel.setVisible(true); //frame.getContentPane().add(this.jPanelNorth, java.awt.BorderLayout.EAST); this.frame.getContentPane().add(this.scrollPanePanel, java.awt.BorderLayout.EAST); // component est ma zone de dessin que je passe en paramètre au constructeur this.frame.getContentPane().add(component, java.awt.BorderLayout.CENTER); this.frame.pack(); this.frame.setVisible(true); } }
Est-ce que quelqu'un aurait une idée?
Merci d'avance
Partager