Bonjour,
je voudrais positionner mon JLabel au centre horizontalement comme un centre sous word.

Avec un Label en axt j'utilisatt : setAlignement(1).
Avec un Jlabel j'ai essayer setAlignementX et Y, mais cela ne change rien du tout...

Voici le code de ma classe Plateau :

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
 
public class Plateau extends JPanel
{
	private JLabel pacman;
	private JLabel vie;
	public Plateau()
	{
		super();
		//Ajout de la bordure
		this.setBackground(Color.WHITE);
		this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
 
		pacman = new JLabel("PACMAN");
		vie = new JLabel("Vie(s) : ");
 
		this.setLayout(new BorderLayout());
		this.add(pacman, BorderLayout.NORTH);
		pacman.setAlignmentY(JComponent.CENTER_ALIGNMENT);
		pacman.setAlignmentX(JComponent.CENTER_ALIGNMENT);
		this.add(vie, BorderLayout.SOUTH);
	}
}
Merci de votre aide