Search code examples
javaswinglayout-managerborder-layout

Java BorderLayout stretch east


Is it possible to make the east (or west) side of a BorderLayout to spread over the entire panel (include north/south)?

enter image description here


Solution

  • Just remove West and East from this panel and create a new "parent" panel:

    JPanel newPanel = new JPanel();
    newPanel.setLayout(new BorderLayout());
    
    newPanel.add(westernPanel, BorderLayout.WEST);
    newPanel.add(yourOldPanel, BorderLayout.CENTER);
    newPanel.add(eastenPanel, BorderLayout.EAST);