Bonjour,

Depuis un grid Layout j'ajoute des JLabel, tout marche bien seulement lorsque je crée mon JLabel custom il y a un soucis avec l'affichage.
Quand j'utilise un JLbale j'ai ce rendu :
Nom : Capture.PNG
Affichages : 53
Taille : 29,6 Ko

Et quand j'utilise ma propre classe héritant de Jlabel j'ai ça :
Nom : Capture.PNG
Affichages : 50
Taille : 8,9 Ko

Voici mon code de mon JLabel custom :

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
public class LabelCustom extends JLabel{
 
	int x;
	int y;
 
	public LabelCustom(int x, int y) {
		super();
		this.x = x;
		this.y = y;
		this.setBackground(Color.white);
		this.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
	}
 
	public int getX() {
		return x;
	}
 
	public void setX(int x) {
		this.x = x;
	}
 
	public int getY() {
		return y;
	}
 
	public void setY(int y) {
		this.y = y;
	}
 
}
Et comment je l"utilise :

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
JPanel j = new JPanel();
		j.setLayout(new GridLayout(nbCaseY, nbCaseX));
 
		for(int i=0; i<nbCaseY; i++) {
			HashMap<Integer, JLabel> ligne = new HashMap();
			for(int y=0; y<nbCaseX; y++) {
				LabelCustom p = new LabelCustom(i, y);
				p.addMouseListener(ml);
				//p.setBounds(100+ y*(hauteur), 100 + i*( hauteur), hauteur, hauteur);
				p.setPreferredSize(new Dimension(hauteur, hauteur));
 
				//p.setBounds(100+ y*( (width-200-2*hauteur)/nbCaseX), 100 + i*( (height-200)/nbCaseY), ((width-200-2*hauteur)/nbCaseX), ((height-200)/nbCaseY));
				p.setTransferHandler(new TransferHandler("icon"));
				p.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
 
				p.setOpaque(true);
				p.setVisible(true);
				j.add(p);
				ligne.put(y, p);
			}
			Frame.p.getListeNiveau().get(0).ajouterLigne(ligne);
		}