Reputation: 25
This is a mock up for what I have in mind as a layout for my project:
The way I tried to accomplish this is:
I set the entire frame to a border layout and then cut it horizontally with two panels, we'll call them north and south panels. The south panel is Panel 3 from the first picture.
I set the north panel to a border layout as well and cut it vertically with two panels. These become panel 1 and panel 2 in the first picture. The problem occurs when I try to resize the window. I would like the panels to scale proportionally to eachother so the size ratio's between the panels stay the same. The problem is, instead of resizing, the panels just move away from each other like so:
Any ideas for creating the desired design? Am I on the right track or is there another swing layout that is better suited to my needs?
Upvotes: 0
Views: 128
Reputation: 324197
I would like the panels to scale proportionally to eachother so the size ratio's between the panels stay the same.
Try using a horizontal BoxLayout
. I believe it will allocate extra space proportionally up to the components maximum size if extra space is available.
Or if that doesn't work you can use a GridBagLayout
. You can use the weightx
constraint for each component you add to the panel. This will control how much extra space is given to each component.
Read the section from the Swing tutorial on Layout Managers for working example of each.
Upvotes: 2