Well, I am completely new in this forum so Hi. I hope you guys can help me out. I have tried to extend
JButton to be able to change the background color without loosing the gradient look. I grabbed some code found in this forum (hardcoded som values)...
class JButtonG extends JButton
{
private Color color1;
private Color color2;
private Color color3;
public JButtonG()
{
}
public JButtonG(String lab)
{
super.setText(lab);
this.color1 = Color.WHITE;
this.color2 = Color.RED;
this.color3 = new Color(236, 236, 236);
setContentAreaFilled(false);
}
protected void paintComponent(Graphics g)
{
final Graphics2D g2 = (Graphics2D) g;
int w = getWidth();
int h = getHeight();
Color c = ((this.isEnabled())? color2 : color3);
GradientPaint gradient =
new GradientPaint(20, 0, color1, 20, h, c, false);
g2.setPaint(gradient);
g2.fillRect(0, 0, w, h);
super.paintComponent(g);
}
}
... which works beatifully, except the border on rollover. The above code will change the background on the button to red but when the mouse is over the button a border appear, which is blue. I guess the default color of the button.
How can I change the color of the extended JButton?
Thanks, O.