How to use layers to write my 2D game

I am trying to use java.awt.Panel as a layer but is not working because i cant set the full transparency of the panel’s background.

I am trying this, but does not set the panel’s background alfha channel



Color cl = new Color(0,0,0,0.5f);
Panel.setBackground(cl);


the color still 100% black on panel’s background.

Thanks
Rodrigo.

You won’t get transparancy with java.awt.Panel any time soon. In AWT land Components must fill their rectangle.

You may be able to do what you desribe with a javax.swing.JPanel and a javax.swing.JLayeredPane or if you only need two layers than the contentPane and glassPane of a JPanel may be enough. I personally haven’t tried that so it may not work.

Finally you could create an in memory image and do your compositing in it before you paint it to a Panel.

panels.setOpaque (false);

This works with most components, but not frames, tree, list,etc.

If you want to used layered rendering mixed with swing stuff have a look at http://developer.java.sun.com/developer/Books/2dgraphics/glfWebAll.zip. Its a Graphics framework from Sun which simplifies alot of layered rendering work.
Harley.

The command setOpaque(boolean) from JComponent realy does not work with any of its subclasses (JPanel, JInternalFrame).

No matter the method isOpaque() return false, the Component still opaque.

Someone can explain it.

thx.

i’m not sure if this good advice but you might try an overlayLayout on a JPanel.