在一个 JFrame 中的不同 JPanel 之间切换,无需 CardLayout 按钮
我是 Java GUI 的新手,我正在尝试制作一个显示登录屏幕并在登录后显示菜单的程序。 我正在寻找一种在一个 JFrame 中浏览不同 JPanel 的方法。要导航,用户应使用这些面板内的按钮。
我使用 Netbeans 来执行此操作。我最远的是在 JFrame 中打开一个 JPanel,我一直在尝试关闭一个并打开另一个,但它不起作用,因为当前面板保持打开状态。
我不想使用 CardLayout 的原因是因为我不希望选项卡可见。我不认为你可以隐藏它们......
我希望你们能帮助我,
提前谢谢!
I'm new at Java GUI and I'm trying to make a program that shows a login screen and once logged in, a menu.
What I am looking for is a way to navigate through different JPanels in just one JFrame. To navigate the user should use buttons located inside these panels.
I use Netbeans to do this. The furthest I got is to open one JPanel in a JFrame, I've been trying to close one and open another but it won't work because the current panel stays open.
The reason I do not want to use the CardLayout is because I do not wish to have to tabs visible. I don't think you can hide them...
I hope you guy's can help me out,
thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CardLayout 完全符合您的要求,并且绝对不需要您使用选项卡。事实上,关于卡片布局的java教程提供了一个演示使用组合框在不同的卡之间进行更改。
CardLayout does exactly what you want and absolutely does not require you to use tabs. In fact, the java tutorial on card layout provides a demo that uses a combobox to change between different cards.
听起来你想实现一个 向导 或类似的。查看链接的文章。
Sound like you want to implement a wizard or similar. Take a look at the linked article.
只需从
contentPane
中删除面板并添加您想要显示的新面板即可。当按下按钮时,这必须通过代码来完成,并且可以切换到下一个面板。Simply remove the panel from the
contentPane
and add the new you want to show. This have to be done by code when the button is pressed and all it's ok to change to the next panel.