Bonjour à toute et à tous,

Aujourd'hui je suis confronté à un problème que je ne sais pas résoudre. J'ai beau cherché rien ne fonctionne. Je vous explique.

J'ai une JFrame contenant un JPanel qui s'occupe d'afficher une image et dans ce JPanel j'en ai un autre qui doit m'afficher à l'aide d'un gridbaglayout deux champs de saisie. Tout est bien positionné mais ma photo d'arrière plan ne s'affiche pas ? ! Pourquoi ? !

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
public class Fenetre extends JFrame
{
	// Déclarations des variables
		private PanneauImage panneau = new PanneauImage();
 
	//	Constrcuteur
		public Fenetre()
 
		{
			this.setTitle("Projet: La transcription d'ADN");
			this.setLayout(new BorderLayout());
			this.setSize(400,283);
			this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			this.setLocationRelativeTo(null);
			this.setVisible(true);
			this.setResizable(false);
			this.add(panneau);		
		}
}
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
public class PanneauImage extends JPanel 
{
	// Déclarations et initialisations des variables
		private Panneau1 panneauCentral = new Panneau1();
 
	// Constrcuteur
		public PanneauImage()
		{
			this.setLayout(new BorderLayout());
			this.add(panneauCentral);
		}
 
	// Méthode  
		  public void paintComponent(Graphics g)
		  {
			    try 
			    {
			        Image img = ImageIO.read(new File("tube_sanguin.jpg"));
			        g.drawImage(img, 0, 0, this);
			        //Pour une image de fond
			        //g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
			     } 
			    catch (IOException e) 
			    {
			        e.printStackTrace();
			    }               
		  } 
}

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
public class Panneau1 extends JPanel
{
	// Déclarations et initialisations des variables
		private JTextField saisieNom = new JTextField("");
		private JTextField saisiePrenom = new JTextField("");
		private JLabel nom = new JLabel("Nom : ");
		private JLabel prenom = new JLabel("Prénom : ");
 
	// Constructeur
		public Panneau1()
		{
 
			this.setPreferredSize(new Dimension(200,141));
			this.setLayout(new GridBagLayout());
 
		    GridBagConstraints gbc = new GridBagConstraints();
 
		    // Ajout de JtextField Nom
			    gbc.gridx = 0;
			    gbc.gridy = 0;
			    gbc.gridheight = 1;
			    gbc.gridwidth = 1;
			    gbc.anchor = GridBagConstraints.LAST_LINE_START;
			    this.add(nom, gbc);
 
			// Ajout de JLabelNom
			    gbc.gridx = 1;
			    gbc.gridheight = 1;
			    gbc.gridwidth = 1;
			    saisieNom.setPreferredSize(new Dimension(150,30));
			    this.add(saisieNom, gbc);
 
		    gbc.gridwidth = GridBagConstraints.REMAINDER;
 
		    // Ajout de JtextField Prénom
			    gbc.gridx = 0;
			    gbc.gridy = 1;
			    gbc.gridheight = 1;
			    gbc.gridwidth = 1;
			    gbc.anchor = GridBagConstraints.LAST_LINE_START;
			    this.add(prenom, gbc);
 
			// Ajout de JLabel Prénom
			    gbc.gridx = 1;
			    gbc.gridheight = 1;
			    gbc.gridwidth = 1;
			    saisiePrenom.setPreferredSize(new Dimension(150,30));
			    this.add(saisiePrenom, gbc);
 
		}
 
}
Voici mes trois classes, j'ai l'impression que le problème vient d'un repaint mais bon j'utilise paintComponent et il n'existe pas de repaintComponent. Peut-être un problème de Super paintComponent() ?

Amicalement crodilus.