I'm trying to add 3 panels to the border layout only North South and West
something like
[A]
___ ______________
| || P2 |
| ||______________|
|P1 | ______________
| || P3 |
|___||______________|
I try to do something like
JFrame window = new JFrame();
window.setLayout(new BorderLayout());
window.add(P1, BorderLayout.WEST);
window.add(P2, BorderLayout.NORTH);
window.add(P3, BorderLayout.SOUTH);
It ends up like
[B]
______________
| P2 |
|______________|
___
|P1 |
|___|
______________
| P3 |
|______________|
Do I have to add like a gap as the Center to avoid the issue? I tried just putting P2 and P3 into another Big panel and adding, P1 - West and Big Panel- Center is there any other way around this? Or should I just try a different Layout.
That's just the way that BorderLayout works; the NORTH and SOUTH components extend horizontally over and under the WEST, CENTER, and EAST components.
Your system with two BorderLayouts is perfectly fine. You could achieve the same thing with GridBagLayout or MigLayout, but I'll guarantee you it'd take much longer to implement. Using intermediate panels is a valid way to do things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With