简体   繁体   English

您如何在JPanel中拉伸JPanel?

[英]How do you stretch a JPanel within a JPanel?

Here is an image of what I'm working with: 这是我正在使用的图像: 在此输入图像描述

And Here is what I would like to acheive: 这就是我想要实现的目标: 在此输入图像描述

As you can see, I have an JPanel Outer with a GridLayout of (3, 1)...ie 3 row and 1 column 如您所见,我有一个JPanel外部,其GridLayout为(3,1)...即3行和1列

I added 3 JPanels within the Outer JPanel, but the problem I have is stretching just the Inner2 JPanel. 我在外部JPanel中添加了3个JPanels,但是我遇到的问题是仅拉伸Inner2 JPanel。 I need more space to add more info in Inner2 and want less space for Inner3 because it only has a CHECKOUT JButton. 我需要更多空间来在Inner2中添加更多信息,并希望Inner3的空间更少,因为它仅具有CHECKOUT JButton。

How would I go about achieving this? 我将如何实现这一目标?

I have tried to set different layouts within Inner2 but it seems like the dimension of all the Inner JPanels are FIXED. 我试图在Inner2中设置不同的布局,但是似乎所有内部​​JPanel的尺寸都是固定的。

Don't use a GridLayout because the components will always be the same size. 不要使用GridLayout,因为组件的大小将始终相同。

Maybe you can use a BoxLayout or GridBagLayout . 也许您可以使用BoxLayoutGridBagLayout Or maybe even a BorderLayout would be better to use since it allows the CENTER panel to grow as much as it needs. 也许甚至使用BorderLayout也会更好,因为它允许CENTER面板根据需要增长。

Read the section from the Swing tutorial on Using Layout Managers for an example of using the above layouts. 阅读Swing教程中有关使用布局管理器的部分,以获取使用上述布局的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM