Ignacio
Ignacio

Reputation:

Stacking JPanels on top of other

I have created 5 very similar panels that are suppuosed to be visible in the same area of a frame on at a time, What I mean is that when the app stars one of them (JPanel0) is visible and the other four are created but invisible and when i hit Button1, JPanel1 sets to visible and JPanel0 goes invisible, same with all.

I manage to get close with the BorderLayout But I cant get all of them to be centered in what would be the center position. Can someone help me? Thank you very much!

Upvotes: 1

Views: 423

Answers (2)

Eugene Ryzhikov
Eugene Ryzhikov

Reputation: 17369

Another option would be to use OverlayLayout.

Upvotes: 0

coobird
coobird

Reputation: 161042

Could CardLayout be what you may be looking for?

The Java Tutorials has an article on How to Use CardLayout, which includes an example which switches between a couple of JPanels which get swapped by using CardLayout.

Upvotes: 5

Related Questions