1

I have two transparent overlapping JPanel both inside of a container panel, using CardLayout. I have components inside both panels, but even if they are both transparent, it is showing only the components inside the panel added for first inside the container:

panel1.setOpaque(false);
panel2.setOpaque(false);
container.setLayout(new CardLayout(0, 0));
container.add(panel1); //only components inside panel1 are shown
container.add(panel2); //if I change order, only components in panel2 are shown

Since I have buttons in panel1 and labels in panel2 (I need them to be like this), I would like to make both panels' components visible.

Koosshh56
  • 317
  • 3
  • 17

1 Answers1

1

You can use the OverlayLayout.

This layout is designed to display two components on top on one another.

The Swing tutorial doesn't have an example of this layout so you can check out: Java Layout with Component always in Top Right for an example to help demonstrate how the layout works.

Community
  • 1
  • 1
camickr
  • 321,443
  • 19
  • 166
  • 288