简体   繁体   中英

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

I added 3 JPanels within the Outer JPanel, but the problem I have is stretching just the 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.

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.

Don't use a GridLayout because the components will always be the same size.

Maybe you can use a BoxLayout or GridBagLayout . Or maybe even a BorderLayout would be better to use since it allows the CENTER panel to grow as much as it needs.

Read the section from the Swing tutorial on Using Layout Managers for an example of using the above layouts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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