I have the following problem:
I have my own instance of JPanel to create an ImageButton. When I set a background, it automatically adds a color gradient, which causes the transparent image to have a background that doesn't fit the color of my JFrame.
How can I remove this gradient?
public ImageButton(Runnable exec, boolean on) {
super();
setBackground(new Color(238,238,238));
setVisible(false);
switched_on = on;
setSize(new Dimension(64, 64));
setPreferredSize(new Dimension(64, 64));
if(on) {
img = ImageButton.on;
}else{
img = ImageButton.off;
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0, 0, null);
}
Screenshot: ImageButton
Another Screenshot, where you see the gradient better