Java - JPanel 和 JPanel其内容如何设置边界
我的 JFrame 上有 3 个 JPanel。无论如何,当 JFrame 调整大小时,JPanel 会垂直和水平扩展,它们绑定到 JFrame。
我想知道如何将其中一个 JPanel 内部的 JScrollPane 设置为绑定到该 JPanel,这样如果该 JPanel 正在调整大小,那么其中的 JScrollPane 也会被调整。
I have 3 JPanels on my JFrame. Anyhow the JPanels expand vertically and horizontally as the JFrame is being re-sized they are bound to JFrame.
I am wondering how do i set JScrollPane that is inside one of the JPanels to be bound to that JPanel so if that JPanel is being re-sized so is the JScrollPane inside it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有一个仅包含一个应随面板缩放的
JComponent
的JPanel
,那么最简单的布局管理器选项之一是BorderLayout
并添加中心的内容有一个完整的 Swing 教程布局管理器描述了在什么情况下不同的管理者是最适合的
If you have a
JPanel
containing only oneJComponent
which should scale with the panel, one of the easiest layout manager options is theBorderLayout
and adding the contents in the centerThere is a whole Swing tutorial on the different layout managers which describes in which situations the differentmanagers are most suited
这需要您根据需要为 JPanel 提供正确的布局,例如 BorderLayout、GridLayout、BoxLayout 或其他布局(但不是 JPanel 的默认布局 - FlowLayout - 它不会更改所持有组件的首选大小)。如果是 BorderLayout,则添加 JPanel
BorderLayout.CENTER
(或根据需要再次添加到其他位置)。如果您不熟悉基本布局,您需要阅读并学习可以在此处找到的教程:课程:在容器内布置组件
This would require you to give the JPanel a correct layout such as a BorderLayout, GridLayout, BoxLayout, or other depending on the need (but not JPanel's default layout -- FlowLayout -- which does not change the preferredSize of the components held).. If a BorderLayout, then add the JPanel
BorderLayout.CENTER
(or in another position again depending on need). If you are not familiar with the basic layouts, you will want to read through and study the tutorials which can be found here:Lesson: Laying Out Components Within a Container