java - JPanel remove color gradient -
i have following problem:
i have own instance of jpanel create imagebutton. when set background, automatically adds color gradient, causes transparent image have background doesn't fit color of jframe.
how can remove 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, see gradient better
when set background, automatically adds color gradient, causes transparent image have background doesn't fit color of jframe.
make panel transparent:
setopaque( false ); now both image , panel transparent background color background of parent component of imagepanel.
although easier approach use jlabel. jlabel transparent default. can use seticon(...) method change image. there no need custom painting or custom component.


Comments
Post a Comment