Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Borderlayout gui adding to borders

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.

like image 838
Thao Nguyen Avatar asked Mar 28 '26 23:03

Thao Nguyen


1 Answers

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.

like image 200
Ernest Friedman-Hill Avatar answered Apr 02 '26 07:04

Ernest Friedman-Hill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!