将 JPanel 堆叠在其他面板之上
我创建了 5 个非常相似的面板,它们应该一次在框架的同一区域中可见,我的意思是,当应用程序加注星标时,其中一个面板 (JPanel0) 可见,而其他四个面板已创建但不可见当我点击 Button1 时,JPanel1 设置为可见,JPanel0 变为不可见,与所有相同。
我设法接近 BorderLayout 但我无法让它们全部集中在中心位置。 有人能帮我吗? 非常感谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以
CardLayout
是您正在寻找的吗?Java 教程 有一篇关于 如何使用 CardLayout,其中包括一个在几个
JPanel
通过使用CardLayout
进行交换。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
JPanel
s which get swapped by usingCardLayout
.另一种选择是使用 OverlayLayout。
Another option would be to use OverlayLayout.