Bonjour à tous,

J'ai un problème tous bête :
J'ai une JFrame dans laquelle j'ai ajouté un JPanel.
Ensuite j'ajoute dans mon JPanel un JScrollPane et un autre JPanel que nous appelerons JPanel2. Mes fenetres s'affiche sauf que le contenu de mon Jpanel2 ne s'affiche pas.

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
 
JPanel mainPanel = new JPanel();
 
setTitle( "Basic JTable in a JPanel" );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
 
JTable jTable = new JTable( new ModelStaticObject() );
jTable.setDefaultRenderer( Boolean.class, new GenderCellRenderer() );
jTable.setDefaultRenderer( Color.class, new ColorCellRenderer() );
jTable.getColumnModel().getColumn(1).setCellRenderer( new BoldCellRenderer() );
 
mainPanel.setLayout( new BorderLayout() );
 
JScrollPane jScrollPane = new JScrollPane( jTable );
jScrollPane.setBorder( new LineBorder(Color.RED) );
jScrollPane.setPreferredSize( new Dimension( 700,500 ) );
mainPanel.add( jScrollPane, BorderLayout.CENTER );
 
EastPanel eastPanel = new EastPanel("EastPanel");
eastPanel.setPreferredSize( new Dimension( 700,200 ) );
mainPanel.add( eastPanel, BorderLayout.NORTH );
 
this.setContentPane( mainPanel );
this.setVisible(true);
pack();
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
package com.clearstream.main;
 
import java.awt.GridBagConstraints;
import java.awt.Insets;
 
public class EastPanel extends JPanel {
 
	private static final long serialVersionUID = 1L;
 
	public JPanel eastPanel = new JPanel();
	public JLabel matriculeLabel = new JLabel("Matricule :");
	public JLabel nomLabel = new JLabel("Nom :");
	public JLabel prenomLabel = new JLabel("Prénom :");
	public JLabel fonctionLabel = new JLabel("Fonction :");
	public JLabel sexeLabel  = new JLabel("Sexe :");
	public GridBagConstraints gbc = new GridBagConstraints();
 
	public EastPanel(String name) { 
		initPanel(name);
	}
 
	public void initPanel(String name) {
		this.setName(name);
		//this.eastPanel.setLayout( new GridBagLayout() );
 
		/* a- ajout du label contenant le matricule. */
		this.gbc.gridx = 0;
		this.gbc.gridy = 0;
		this.gbc.gridwidth = GridBagConstraints.REMAINDER; // gbc.gridheight = 1;
		this.gbc.insets = new Insets(0, 5, 0, 0);
		/* Le point d'ancrage ici n'a pas une grande importance. Nous allons quand même essayer d'aligner tout les
		 * composants qui le peuvent sur leur ligne de base. */
		this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		this.eastPanel.add(this.matriculeLabel, gbc);
 
		/* c- étiquette contenant le nom. */
		this.gbc.gridx = 1;
		this.gbc.gridy = 1;
		this.gbc.gridwidth = 1;
		this.gbc.gridheight = 1;
		/* L'étiquette avec le nom sera alignée sur la ligne de base avec le champ de saisie pour le nom. */
		this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		this.gbc.insets = new Insets(0, 5, 0, 0);
		this.eastPanel.add(this.nomLabel, gbc);
 
	    /* e- l'étiquette pour le prénom. */
		this.gbc.gridx = 1;
		this.gbc.gridy = 2;
		this.gbc.gridwidth = 1;
		this.gbc.gridheight = 1;
		this.gbc.fill = GridBagConstraints.NONE;
		this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		this.gbc.insets = new Insets(0, 5, 0, 0);
	    this.eastPanel.add(this.prenomLabel, gbc);
 
	    /* g- l'étiquette pour la fonction. */
	    this.gbc.gridx = 1;
	    this.gbc.gridwidth = 1;
	    this.gbc.gridheight = 1;
	    this.gbc.gridy = 3;
	    this.gbc.fill = GridBagConstraints.NONE;
	    this.gbc.anchor = GridBagConstraints.BASELINE_LEADING;
	    this.gbc.insets = new Insets(0, 5, 0, 0);
	    this.eastPanel.add(this.fonctionLabel, gbc);
 
	}
}
Si quelqu'un a une petite idée merci d'avance