Search code examples
javaswingtransparencyjbuttonrgba

jbutton RGBA glitch


I am using RGBA for the coloring. I want the button transparent, but to be able to set the degree of transparency, hence the alpha. Now it looks fine until I do anything that calls a repaint/paint like hover or focus. If I set opaque to false, it does make it transparent, I just don't want this 100% transparent. It is not the image I paint in the background either. It does not have a problem with RGB, just RGBA.

these don't work:

jButton1.setContentAreaFilled(true or false);
jButton1.setOpaque(true or false);

Here is my jButton color code:

jButton1.setBackground(new Color(255,0,0,100));

Here is what it looks like.jbutton glitch


Solution

  • Your problem looks something like this. The answers there may help you get the translucency right, but you'll need to do it in a custom ButtonUI, illustrated here.

    Before: before

    After: after

    ButtonUI: buttonui