Question

I'm writing a game which uses a border layout with a JPanel using BorderLayout.CENTER. What I'd like to be able to do is sometimes hide this panel and replace it with another panel with different information. I added both to the container and set visibility of one of them to false.

Then later I try:

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

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

TIA

Was it helpful?

Solution

Use a nested JPanel with a CardLayout for that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top