0

I have an undecorated and translucent Window in Swing, the jLabels on it are translucent as well. As i set the background with .setBackground() and using a the constructor of Color like new Color(int a, int b, int c, int d) it works. The problem is, that when i repaint the jLabel after a mouse entered event or similar and i change the background i seems like it would add a sort of new layer of translucent paint. It looks like it would increase the alpha although the color is defined in a separate class with constants.

  • Swing components are either transparent or opaque, they don't know how to paint alpha based backgrounds. Instead, you need to "fake" it, but making the component fully transparent and painting the background (by overriding `paintComponent`) and filling it with the translucent color – MadProgrammer Apr 21 '16 at 21:51
  • hm, i'm working on a mac and making labels opaque, seems to just make them transparent. If i use the AlphaContainer or if i just override the paint method doesn't make any difference... – Pietro Pozzoli Apr 21 '16 at 23:40
  • So am I (using a Mac), you need to make them transparent (`setOpaque(false)`) and override the `paintComponent` to paint the alpha based color. As you can see from my the example linked in the duplicate question, the screenshot is from a Mac. Make sure that you run the example as it is, without modification first and then try and see how you could incorporate it. – MadProgrammer Apr 21 '16 at 23:47
  • Alright, thanks! I made wrappers for every kind of stuff; works great! Only a JPanel with inside a JscrollPane with inside a JTextArea doesn't seem to want to get transparent?! – Pietro Pozzoli Apr 23 '16 at 10:37
  • `JScrollPane` has a `JViewport` onto which components are placed, you need to make the `JViewport` transparent as well, for [example](http://stackoverflow.com/questions/13677850/add-background-image-in-jtable/13678077#13678077), [example](http://stackoverflow.com/questions/30339103/transparent-jlist-in-jscrollpane-all-in-one-class/30339125#30339125) and [example](http://stackoverflow.com/questions/14761598/write-text-into-a-jtextpane-with-an-image-background/14763273#14763273) – MadProgrammer Apr 23 '16 at 11:26

0 Answers0