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.
我创建了5个非常相似的面板,这些面板一次只能在一个框架的同一区域中可见,我的意思是当应用程序中的一个(JPanel0)可见而其他四个被创建但看不见时当我点击Button1时,JPanel1设置为可见,JPanel0变为不可见,与所有相同。
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!
我设法与BorderLayout接近但我不能让他们所有人都集中在中心位置。有人能帮我吗?非常感谢你!
2 个解决方案
#1
Could CardLayout
be what you may be looking for?
CardLayout可能是你想要的吗?
The Java Tutorials has an article on How to Use CardLayout, which includes an example which switches between a couple of JPanel
s which get swapped by using CardLayout
.
Java Tutorials有一篇关于如何使用CardLayout的文章,其中包含一个在使用CardLayout交换的几个JPanel之间切换的示例。
#2
Another option would be to use OverlayLayout.
另一种选择是使用OverlayLayout。
#1
Could CardLayout
be what you may be looking for?
CardLayout可能是你想要的吗?
The Java Tutorials has an article on How to Use CardLayout, which includes an example which switches between a couple of JPanel
s which get swapped by using CardLayout
.
Java Tutorials有一篇关于如何使用CardLayout的文章,其中包含一个在使用CardLayout交换的几个JPanel之间切换的示例。
#2
Another option would be to use OverlayLayout.
另一种选择是使用OverlayLayout。