Is it possible to have 2 JPanels in the border layout at the same place?

I am writing a game that uses a border layout with a JPanel using BorderLayout.CENTER. What I would like to do is sometimes hide this panel and replace it with another panel with different information. I added both containers and set the visibility of one of them to false.

Then I will try:

panel1.setVisible(false);
panel2.setVisible(true);

      

but that doesn't display the new panel. I just see gray. Any ideas?

TIA

+2


source to share


1 answer


Use a nested JPanel with CardLayout for this.



+5


source







All Articles