Search code examples
javaborder-layout

Border Layout setting component at EAST to cover full space at the right


I have components placed in a border layout at CENTER , SOUTH and EAST. The problem is that default, the component at the SOUTH takes the whole bottom space. But dont want to let the south component to take the space of right panel too. Here is the image :- https://www.dropbox.com/s/8slbh7y88ri1lyn/Untitled.png It is possible by putting a border layout inside other border layout but I can't do that.


Solution

  • It is possible by putting a border layout inside other border layout but I can't do that.

    As I suggested in my comment this is in fact the correct way to go about this.

    // assume "main" is your current top-level container
    main.setLayout(new BorderLayout());
    main.add(rightPanel, BorderLayout.EAST);
    JPanel leftColumn = new JPanel();
    leftColumn.setLayout(new BorderLayout());
    main.add(leftColumn, BorderLayout.CENTER);
    
    leftColumn.add(bottomPanel, BorderLayout.SOUTH);
    leftColumn.add(centerPanel, BorderLayout.CENTER);
    

    Now there is no SOUTH component in the main layout, so the rightPanel will take up the full vertical space. The bottomPanel will take up the south area of the space allocated to the leftColumn and the centerPanel will get the remaining space at the top left.