How to make transparent JLayeredPane () and JPanel ()? It always shows the background of the super window.

How can I completely make the gray panel transparent so that I can only see the Test button, but not the gray window (JPanel or JLayeredPane)

Screenshot: enter image description here

public class win extends JWindow { ... public win() { super(new JFrame()); layers = new JLayeredPane(); button = new JButton("close"); this.setLayout (new BorderLayout ()); .. button.setBackground(Color.RED); button.setSize(200,200); button.setLocation(0,20); this.add("North", button); JPanel p = new JPanel(); p.setOpaque(false); p.setSize(300, 200); p.setLocation(0, 0); p.add(new JButton("Test")); layers.add(p, new Integer(1)); layers.setSize(400,300); layers.setLocation(400,50); layers.setOpaque(false); this.add("North", layers); canvas.setSize(screenSize.width,screenSize.height); this.add("North",canvas); //com.sun.awt.AWTUtilities.setWindowOpacity(this, 0.5f); // gives error in my Java version } } 

Subsequent: installed as recommended, but so far failed.

 ERROR not solved: Exception in thread "main" java.lang.UnsupportedOperationException: The TRANSLUCENT translucency kind is not supported. Installed: compiz-gnome.i686 0:0.9.4-2.fc15 Dependency Installed: compiz-gtk.i686 0:0.9.4-2.fc15 compiz-plugins-main.i686 0:0.9.4-1.fc15 libcompizconfig.i686 0:0.9.4-1.fc15 protobuf.i686 0:2.3.0-7.fc15 Complete! You have mail in /var/spool/mail/root [ root@example ~]# xdpyinfo | grep -i render RENDER You have mail in /var/spool/mail/root [ root@example ~]# xdpyinfo | grep -i comp Composite XVideo-MotionCompensation [ root@example ~]# 
+4
source share
1 answer

See this article or this article . Please note that not all environments support all the functions (transparency, pixel transparency, etc.) described in the article.

EDIT . On my system (Ubuntu 10.04.2 LTS, Sun java 1.6.0_26) the following code is given:

  System.out.println("TRANSLUCENT supported: " + AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.TRANSLUCENT)); System.out.println("PERPIXEL_TRANSPARENT supported: " + AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.PERPIXEL_TRANSPARENT)); System.out.println("PERPIXEL_TRANSLUCENT supported: " + AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT)); 

gives:

 TRANSLUCENT supported: false PERPIXEL_TRANSPARENT supported: true PERPIXEL_TRANSLUCENT supported: true 

EDIT2: Inspired by this discussion , I just installed and configured compiz , and now the “permanent opacity” level of the “slider” of the web launch application in the second article linked above can be moved to values ​​less than 100%, and the demo frame is actually translucent . Also, the snapshot shown above now prints true for all three types of transparency / transparency. And AWTUtilities.setWindowOpacity(..) no longer throws, but creates a transparent window.

+4
source

All Articles