[英]Java JPanel in BorderLayout positioning
Can I expand a child panel all the way from BorderLayout.LINE_START
to BorderLayout.LINE_END
, fill all the space from right to left including the center ? 我是否可以从
BorderLayout.LINE_START
一直扩展到BorderLayout.LINE_END
整个子面板,从右到左填充所有空间,包括中心?
I am trying to accomplish as below... 我正在尝试实现以下目标...
+-------------------------+
| |
+-------------------------+
| PANEL OCCUPYING |
| ALL THIS |
| SPACE |
+-------------------------+
| |
+-------------------------+
That looks like the CENTER
of the BorderLayout. 看起来像BorderLayout的
CENTER
。
Read the section from the Swing tutorial on How to Use BorderLayout for more information and examples. 阅读Swing教程中有关如何使用BorderLayout的部分, 以获取更多信息和示例。
for some reason, I keep getting empty spaces on the right and left...
由于某种原因,我一直在左边和右边留出空白...
The CENTER
will occupy all the space available. CENTER
将占据所有可用空间。 So it depends on the component that you add to the CENTER
. 因此,这取决于您添加到
CENTER
的组件。 Maybe you are adding a panel and the panel expands, but the component on the panel doesn't expand because by default a panel uses a FlowLayout
and FlowLayout respects the preferred size of the components added to it. 也许您要添加一个面板,并且该面板会展开,但是该面板上的组件不会展开,因为默认情况下,面板使用
FlowLayout
并且FlowLayout会考虑添加到其中的组件的首选大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.