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

https://i.stack.imgur.com/hen6k.png

another screenshot, see gradient better

https://i.stack.imgur.com/k8efl.png

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

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -