如何使用 Java Swing 将一堆 JPanel 添加到我的 JFrame 中?
我生成一堆 JPanel,然后将它们传递到扩展 JFrame 的类中。如何向此 JFrame 添加无限数量的 JPanel。我还在阅读有关 JScrollPane 的内容,我是否应该将其以某种方式合并到设计中?
示例代码:
class foo extends JPanel
{
//generate JPanels
}
class bar extends JFrame
{
//grab some amount of foo classes and put them into this JFrame and show it
}
显示此 JFrame 时还有什么需要注意的吗?
谢谢
I generate a bunch of JPanels and then pass them into a class that extends JFrame. How do I add an indefinite number of JPanels to this JFrame. I was also reading about JScrollPane should I incorporate this somehow into the design?
Example Code:
class foo extends JPanel
{
//generate JPanels
}
class bar extends JFrame
{
//grab some amount of foo classes and put them into this JFrame and show it
}
Also is there anything I need to watch out for when showing this JFrame?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CardLayout
、JDesktopPane/JInternalFrame
、JTabbedPane
、JScrollPane
- 有许多选项。(耸肩)
pack()
GUI,然后设置位置并调用setVisible(true)
。CardLayout
,JDesktopPane/JInternalFrame
,JTabbedPane
,JScrollPane
- there are a number of options.(shrugs)
pack()
the GUI before setting the position and callingsetVisible(true)
.JFrame -> JScrollPane ->父亲 JPanel 然后你将决定哪个 LayoutManager 将放置您的
一堆 JPanels
,通过默认 FlowLayout,不要忘记使用 childsPanel 的 PreferedSizeJFrame -> JScrollPane -> fathers JPanel then you'll decide which of LayoutManager will lay your
bunch of JPanels
, by defalut FlowLayout, don't forget to play with PreferedSize for childsPanels