Bonjour,
J'essaie d'afficher un simple label dans une JWindow mais, après de nombreux essais, je commence à m'arracher les cheveux.
Je pense que c'est possible d'afficher un label dans une JWindow mais mon code contient peut-être une erreur ou alors il manque une ligne qui permettrait d'afficher !?!
Voici mon code (la classe AProposAction) :
et la classe FenAPropos qui est instanciée à la ligne 12 de la classe AProposAction :
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 private FenAcceuil fenetreAcceuil; public AProposAction(FenAcceuil fen, String texte) { super(texte); this.fenetreAcceuil = fen; } @Override public void actionPerformed(ActionEvent arg0) { JLabel lab = new JLabel("", JLabel.CENTER); FenAPropos window = new FenAPropos(); window.add(lab); window.setVisible(true); lab.setText("maaaooooo"); fenetreAcceuil.setVisible(false); try { Thread.sleep(5000); } catch (InterruptedException e) {} window.setVisible(false); fenetreAcceuil.setVisible(true); }
Voilà, je pense avoir tout dit, si quelqu'un peut m'aider ce sera avec plaisir !
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 package fenetres; import javax.swing.BoxLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JWindow; public class FenAPropos extends JWindow { /** * */ private static final long serialVersionUID = 1L; public FenAPropos() { super(); build(); } private void build() { setSize(400, 300); setLocationRelativeTo(null); //placement au milieu de l'écran setAlwaysOnTop(true); setContentPane(buildContentPane()); } private JPanel buildContentPane() { JPanel panelAPropos = new JPanel(); panelAPropos.setLayout(new BoxLayout(panelAPropos, BoxLayout.Y_AXIS)); // panelAPropos.setLayout(new FlowLayout()); JLabel label1 = new JLabel("coucou"); panelAPropos.add(label1); return panelAPropos; } }
Merci,
Partager