Bonjour,

Voila mon problème: j'ai un JPanel auquel je rajoute un JButton. Ce JButton s'affichait bien. Depuis j'ai voulu ajouter une image de fond à ce JPanel, j'ai cherché sur le net et trouvé la solution. Seulement maintenant l'image s'affiche bien mais mon JButton a disparu.
Mon code:

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
public PanneauPrincipal() {
        super(new FlowLayout());
 
        couleurFond = new Color(0, 0, 0);
        setBackground(couleurFond);
        couleurTexte = new Color(19, 19, 84);
        couleurTitre = new Color(255, 255, 255);
        // red
        important = new Color(255, 0, 0);
 
        bouton1 = new JButton("Grille 1");
        bouton1.addActionListener(new ActionEntrerListener());
        add(bouton1);    
 
        image = Toolkit.getDefaultToolkit().getImage("images/fond_menu.jpg");
        try {
            jbInit();
        } catch(Exception e) {
            e.printStackTrace();
        }
 
        String filePath = "grille1.txt";
    }    
 
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
 
        g.drawImage(image, 335, 310, null);
        repaint();
    }
 
    private void jbInit() throws Exception {
        this.setLayout(new BorderLayout());
    }
}
Merci!