Bonjour,

Pourquoi le label n'est pas dessiné dans le panel ?

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
 
package pesage;
 
import java.awt.Color;
import java.awt.Graphics;
 
import javax.swing.JLabel;
import javax.swing.JPanel;
 
public class PBascules extends JPanel
{
 
    private static final long serialVersionUID = 1L;
 
    /**
     * This is the default constructor
     */
    public PBascules()
    {
        super();
        initialize();
        this.repaint();
    }
 
    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize()
    {
        this.setBackground(Color.white);
        System.out.println("ICI 1");
    }
 
    public void paintComponent(Graphics g)
      {
        super.paintComponent(g);
        System.out.println("ICI 2");
 
        JLabel labelMessage = new JLabel();
        labelMessage.setText("TEST");
        labelMessage.setLocation(0, 0);
        labelMessage.setVisible(true);
 
      }
}
Merci.