Bonjour,
Voila j'ai des Panels mais j'aimerai spécifier un ordre d'affichage, j ai pensé à ComponentZorder, mais je ne trouve pas de Tuto ou d'exemple. Si vous pouviez eclairer ma lanterne?
Merci d'avance
Version imprimable
Bonjour,
Voila j'ai des Panels mais j'aimerai spécifier un ordre d'affichage, j ai pensé à ComponentZorder, mais je ne trouve pas de Tuto ou d'exemple. Si vous pouviez eclairer ma lanterne?
Merci d'avance
Sinon tu as le CardLayout, c'est pas mal dans ce genre de situations
JLayeredPane aussi.
En fait j 'ai
---------------------------------------------
**********Panel Fixe*****************
---------------------------------------------
***********************************
***********************************
*********Panel avec une scroll barre******
***********************************
***********************************
---------------------------------------------
Les textboxs passe bien sous le Panel fixe, alors que les labels non. Pourquoi?
Difficile à dire sans voir ton code, quel layout as-tu utilisé? comment ajoutes-tu tes composants? dans quel ordre?
Tu trouveras un référencement des layouts dans ce sujet : http://www.developpez.net/forums/sho...d.php?t=528316
Voila,mon application a pour but d'aller lire dans un fichier exel des informations, et de les afficher.
Pour l'affichage, j'ai comme affiché au dessus, un panel fixe en haut et bas de ma fenetre. Au centre j'ai un ScrollPane dans lequel j'affiche les infos.
Dans ce scroll pane j ai 5 panels. Dans ces panels(Appelons les Panel1,2,..,5) j'affiche les infos.
Dans le Panel1 par ex, j'ajoute autant de Panel (Appelons les PanelInfos1,2,...) que j'ai d'infos dans mon exel.
Structure du Panel1 (exemple):
label-textbox-label-textbox-label-textbox. --> PanelInfos1
label-textbox-label-textbox-label-textbox. --> PanelInfos2
label-textbox-label-textbox-label-textbox. --> PanelInfos3
label-textbox-label-textbox-label-textbox. --> PanelInfos4
Voila pour la présentation.
Pour réaliser cela, j'ai une classe (visualisation) qui affiche tout cela:
J ai une autre classe qui va lire dans mon XLS et qui remplit les différentes arraylist pour construire les PanelInfos de mon exemple du dessus. Chaque "PanelInfos" est composé de deux classe:Code:
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237 package Interface; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Label; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.SimpleDateFormat; import java.util.ArrayList; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.border.EtchedBorder; import sources.ExtractionXLS; import sources.ExtractionXML; import sources.FormatageXML; import Interface.Groudreport.GroundReportPnl; import Interface.Groudreport.GroungReportInfos; import Interface.Lastlegreport.LastLegReportInfos; import Interface.Lastlegreport.LastLegReportPnl; import Interface.Previouslegreport.PreviousLegReportInfos; import Interface.Previouslegreport.PreviousLegReportPnl; import Interface.Totalflighttime.TotalFlightTimePnl; import Interface.Troubleshootdata.TroubleShootDataInfos; import Interface.Troubleshootdata.TroubleShootDataPnl; public class Visualisation extends JFrame implements ActionListener { private JPanel MasterPnlVisu; private int AppliWidth; private int AppliHeight; private JPanel PnlTitle; private static Label PN; private static Label SN; private Label Titre; private static Label DateDay; private JPanel PnlInfos; private JScrollPane ScrollInfos; private TotalFlightTimePnl TotalFlightTime; private static LastLegReportPnl LasLegReport; private static PreviousLegReportPnl PreviousLegReport; private static GroundReportPnl GroundReport; private static TroubleShootDataPnl TroubleShootData; private JPanel PnlBtn; private JButton BtnPrint; private Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); public Visualisation(String Type) { this.setTitle("aa"); AppliWidth = screenSize.width/2+425; AppliHeight = screenSize.height-65; /*-------------------------------Le panel de fond--------------------------------------*/ MasterPnlVisu = new JPanel(); MasterPnlVisu.setPreferredSize(new Dimension(AppliWidth,AppliHeight)); MasterPnlVisu.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); /*-------------------------Le panel de titre---------------------------------------*/ PnlTitle = new JPanel(); //PnlTitle.setComponentZOrder(MasterPnlVisu, 1); PnlTitle.setLayout(new GridBagLayout()); PnlTitle.setPreferredSize(new Dimension(AppliWidth-10,(AppliHeight)*10/100)); PnlTitle.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; MasterPnlVisu.add(PnlTitle,c); if(Type.equals("XLS")) { PN = new Label("P/N: "+ExtractionXLS.GetPartNumber()); } else { PN = new Label("P/N: "+ExtractionXML.GetPartNumber()); } c.fill = c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 1; PnlTitle.add(PN,c); if(Type.equals("XLS")) { SN = new Label("S/N: "+ExtractionXLS.GetSerialNumber()); } else { SN = new Label("S/N: "+ExtractionXML.GetSerialNumber()); } c.fill = c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 1; PnlTitle.add(SN,c); Titre = new Label("AUTO SCAN REPORT"); c.fill = c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 0; PnlTitle.add(Titre,c); DateDay = new Label(); SimpleDateFormat dateStandard = new SimpleDateFormat("dd/MM/yyyy"); if(Type.equals("XLS")) { DateDay.setText(dateStandard.format(ExtractionXLS.GetDate())); } else { DateDay.setText(ExtractionXML.GetDate()); } c.gridx = 2; c.gridy = 1; PnlTitle.add(DateDay,c); /*----------------------------------------------------------------------------------*/ /*--------------------------Le panel pour les infos---------------------------------*/ PnlInfos = new JPanel(); ScrollInfos = new JScrollPane(PnlInfos); //ScrollInfos.setComponentZOrder(MasterPnlVisu, 1); ScrollInfos.setAutoscrolls(true); ScrollInfos.setVisible(true); ScrollInfos.setPreferredSize(new Dimension(AppliWidth-10,(AppliHeight-65)*89/100)); PnlInfos.setLayout(new BoxLayout(PnlInfos,BoxLayout.Y_AXIS)); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 1; MasterPnlVisu.add(ScrollInfos,c); TotalFlightTime = new TotalFlightTimePnl(); PnlInfos.add(TotalFlightTime); PnlInfos.add(LasLegReport); PnlInfos.add(PreviousLegReport); PnlInfos.add(GroundReport); PnlInfos.add(TroubleShootData); /*----------------------------------------------------------------------------------*/ /*----------------------Le panel pour les boutons print et quit---------------------*/ PnlBtn = new JPanel(); PnlBtn.setPreferredSize(new Dimension(AppliWidth-10,30)); PnlBtn.setLayout(new BorderLayout()); //PnlBtn.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)); c.gridx = 0; c.gridy = 2; MasterPnlVisu.add(PnlBtn,c); BtnPrint = new JButton("Imprimer"); BtnPrint.addActionListener(this); BtnPrint.setActionCommand("Print"); PnlBtn.add(BtnPrint,BorderLayout.CENTER); /*----------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------*/ getContentPane().add(MasterPnlVisu); pack(); setVisible(true); } public static void CreatePreviousLegReport(ArrayList<PreviousLegReportInfos> sesInfos) { PreviousLegReport = new PreviousLegReportPnl(sesInfos); } public static void CreateLastLegReport(ArrayList<LastLegReportInfos> sesInfos) { LasLegReport = new LastLegReportPnl(sesInfos); } public static void CreateTroubleShootData(ArrayList<TroubleShootDataInfos> sesInfos) { TroubleShootData = new TroubleShootDataPnl(sesInfos); } public static void CreateGroungReport(ArrayList<GroungReportInfos> sesInfos) { GroundReport = new GroundReportPnl(sesInfos); } public static void SetPn(String text) { PN.setText(text); } public static void SetSN(String text) { SN.setText(text); } public static void SetDateDay(String text) { DateDay.setText(text); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("Print")) { FormatageXML testxml = new FormatageXML(); } } }
La première gère l'affichage du panel en entier (dans l'exemple c'est Panel1):
et la deuxième pour les labels et les textboxCode:
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 package Interface.Troubleshootdata; import java.awt.Label; import java.util.ArrayList; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.border.TitledBorder; import Interface.Previouslegreport.PreviousLegReportInfos; public class TroubleShootDataPnl extends JPanel { public TroubleShootDataPnl(ArrayList<TroubleShootDataInfos> sesInfos) { setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); setBorder(BorderFactory.createTitledBorder(null, "Trouble Shoot Data",TitledBorder.CENTER, 0)); for(TroubleShootDataInfos test : sesInfos) { add(test); } } }
J'espère que je suis assez clairCode:
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 package Interface.Troubleshootdata; import java.awt.Label; import javax.swing.JPanel; import javax.swing.JTextField; import sources.ExtractionXLS; public class TroubleShootDataInfos extends JPanel { private Label LblDateTrbl; private Label LblHeureTrbl; private Label LblTypeTrbl; private JTextField TxtDateTrbl; private JTextField TxtHeureTrbl; private JTextField TxtTypeTrbl; public TroubleShootDataInfos() { LblDateTrbl = new Label("Date :"); LblHeureTrbl = new Label("Heure :"); LblTypeTrbl = new Label("Type :"); TxtDateTrbl = new JTextField(7); TxtHeureTrbl = new JTextField(4); TxtTypeTrbl = new JTextField(30); add(LblDateTrbl); add(TxtDateTrbl); add(LblHeureTrbl); add(TxtHeureTrbl); add(LblTypeTrbl); add(TxtTypeTrbl); } public void SetDate(String Date) { TxtDateTrbl.setText(Date); } public void SetHeure(String Heure) { TxtHeureTrbl.setText(Heure); } public void SetType(String Type) { TxtTypeTrbl.setText(Type); } public String GetDate() { return TxtDateTrbl.getText(); } public String GetHeure() { return TxtHeureTrbl.getText(); } public String GetType() { return TxtTypeTrbl.getText(); } }
Donc au moment ou l'afichage ce fait, tout est correct sauf les labels qui sont normalement caché par les panels sont "toujours premier plan".
Que sont ces composants? PnlInfos à un simple BoxLayout et tu mets tout dedans. Il ne devrait pas y avoir un CardLayout?Code:
1
2
3
4
5 PnlInfos.add(TotalFlightTime); PnlInfos.add(LasLegReport); PnlInfos.add(PreviousLegReport); PnlInfos.add(GroundReport); PnlInfos.add(TroubleShootData);
PnlInfos-----------------------------------
|
|
| TotalFlightTime-------------------------|
| |************taille variable********|
| |--------------------------------------|
|
| LasLegReport--------------------------|
| |************taille variable********|
| |--------------------------------------|
|
| PreviousLegReport----------------------|
| |************taille variable********|
| |--------------------------------------|
|
| GroundReport--------------------------|
| |************taille variable********|
| |--------------------------------------|
|
| TroubleShootData----------------------|
| |************taille variable********|
| |--------------------------------------|
|
--------------------------------------------------------------
En effet c'est simplement un BoxLayout vertical. Mais quel est l'avantage du CardLayout?
Je croyais que tu voulais les informations sous forme d'onglets.
Quels labels sont cachés par quels panels?
Les labels contenu dans les panel :
TotalFlightTime
LasLegReport
PreviousLegReport
GroundReport
TroubleShootData
nessont pas caché par les panel qui sont en tête et pied de pnlInfos alors que j'aimerai qu'il le soit
Quel intérêt de les créer si c'est pour les cacher?
Tu peux faire :Code:pnlInfos.setVisible(false);
J aurais du faire ça dès le début. Regarde bien en haut et en bas du panel avec la scrollbare
http://nsa02.casimages.com/img/2008/...6504073363.jpg
J'ai comme l'impression que tu as mélangé des composants Swing et AWT, en l'occurrence je dirais que tu utilises des Labels à la place de JLabels...
Ah oui j'espère que c'est ça, j'étais en train de me creuser la tête...bien vu sinok :)
Comment dire....:oops:, je vien de faire une belle boullete :D. En effet j ai faitr un meltingpot avec AWT et SWING. Voila c'est réparé. Je suis desolé d'avoir du afficher tant de pixel pour si peu.
Morale: Je le saurais pour la prochaine fois