Bonjour,

Voilà, tout est dans le titre! J'ai fait une classe qui étend de JButton afin que je puisse créer mes boutons que je le souhaite, mais j'aimerai changer la couleur du texte lorsque le bouton est disabled (setEnable(false)) mais impossible, la couleur reste toujours le bleu clair par défaut!

Voilà ma méthode paintComponent (raccourcie, elle est un peu plus complexe mais fonctionne très bien):

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
public void paintComponent(Graphics g) {
	if( ! isEnabled()){
		//marche pas
		//String t = "<html><font color=pink>" + getText() + "</font></html>";
		//setText(t);
 
		//marche pas non plus
		//setForeground(Color.pink);
	}else{
		//marche pas
		String t = "<html><font color=black>" + getText() + "</font></html>";
		setText(t);
 
		setForeground(Color.black);
	}
 
	Graphics2D g2 = (Graphics2D) g;
	g2.setPaint((Paint) new GradientPaint(0, 0, color1, 0, this.getHeight(), color2));
 
	g2.fillRect(3, 3, getWidth() - 6, getHeight() - 6);
 
	super.paintComponent(g);
 
	g2.setColor(Color.black);
 
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
	//taille du cadre
	//g2.setStroke(new BasicStroke(1.9f));
	g2.setStroke(new BasicStroke(1.5f));
	g2.draw(new RoundRectangle2D.Double(1, 1, (getWidth() - 3), (getHeight() - 3), 12, 8));
	g2.drawLine(4, getHeight() - 3, getWidth() - 4, getHeight() - 3);
	g2.dispose();
}
J'ai également essayé de surdéfinir la méthode setEnable afin de changer la couleur, mais rien n'y fait!

Est-ce que qqun a déjà rencontré ce problème ou aurait une idée?

Merci!