Stack of transparent JPanel

Hello everybody,

I'm trying to program an application where I have a stack of Jpanels on my contentPane.

I want all JPanels to be transparent but the "lowest" one, so that I can see essentially the content of all JPanels.

I try it with two JPanles but it seems not to work.

here is my code:

privatevoid createAndShowGUI(){

JFrame frame =new JFrame("MultiplePanels");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(400, 400);

Container pane = frame.getContentPane();

JPanel panel1 =new JPanel(new BorderLayout());

JLabel label1 =new JLabel("label1");

panel1.add(label1, BorderLayout.EAST);

JPanel panel2 =new JPanel(new BorderLayout());

panel2.setOpaque(false);

JLabel label2 =new JLabel("label2");

panel2.add(label2, BorderLayout.WEST);

pane.add(panel1);

pane.add(panel2);

frame.setVisible(true);

}

At the moment it shows only the secon JPanel saying "label2" at the west side of the panel, also I set this panel to be transparent.

Do you know what I'm doing wrong?

Can you help me?

Thank you very much,

Stefan

[1686 byte] By [Stefan-Ulma] at [2007-11-27 8:36:25]
# 1

> pane.add(panel1);

> pane.add(panel2);

Is short for...

> pane.add(panel1, BorderLayout.CENTER);

> pane.add(panel2, BorderLayout.CENTER);

Only one component can be added at a given location. So the second component added replaces the first component.

Read the Swing tutorial on "How to Use Layered Panes":

http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html

camickra at 2007-7-12 20:33:21 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks camickr , I'll do as you said.
Stefan-Ulma at 2007-7-12 20:33:21 > top of Java-index,Desktop,Core GUI APIs...