How can I replace one of two JPanels with another JPanel in Java?(如何在 Java 中用另一个 JPanel 替换两个 JPanel 之一?)
问题描述
我为欢迎屏幕设计了一个界面,其中一个 JFrame 包含两个 JPanel(右侧的 JPanel1 和左侧的 JPanel2).左边的按钮是切换JPanel1中的Panels.我想按下一个按钮来用另一个 JPanel 替换 JPanel1 的内容,但我不知道怎么做.请帮忙.
I designed an interface for the welcome screen with one JFrame included two JPanels (JPanel1 on right and JPanel2 on left). The buttons on the left is to switch the Panels in JPanel1. I want to press on a button to replace JPanel1 content with another JPanel but I don`t know how. Please help.
推荐答案
我发现最好的答案是我将只创建一个 JFrame 并让一个大的 JPanel 包含两个 JPanel(JPanelLeft 包含按钮,JPanelRight 包含按钮的内容做)然后我将为每个 JButton 复制主 JPanel.当我按下任何按钮时,我将执行 (JFrame.getContentPane.removeAll) 以删除旧的 JPanel,然后 (JFrame.getContentPane.Add(NewJPanel).
The best answer I found is that I will create one JFrame only and gonna make one big JPanel include two JPanels (JPanelLeft include the buttons and JPanelRight include what the button do) then I will copy the main JPanel for each JButton. When I press on any button I will do (JFrame.getContentPane.removeAll) to remove the old JPanel then (JFrame.getContentPane.Add(NewJPanel).
这对我有用,并保持我想要的设计.感谢每一个人.
This works for me and keep my design as I Want. Thanks for every body.
这篇关于如何在 Java 中用另一个 JPanel 替换两个 JPanel 之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Java 中用另一个 JPanel 替换两个 JPanel 之一?


基础教程推荐
- 在螺旋中写一个字符串 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01