How to make BorderLayout TOP not fill the whole frame, and Left & Right fill?

Component "A" with borderlayout (with "elements" top, center, bottom) needs to be put into CENTER of another container "B" with borderlayout (with elements of left, right, center aka "A")
public class TestFrame1 extends JFrame { public TestFrame1 () { setSize ( 400, 400 ) ; setLayout ( new BorderLayout () ) ; setDefaultCloseOperation ( DISPOSE_ON_CLOSE ) ; // left final JPanel leftPanel = new JPanel () ; leftPanel.setBackground ( Color.BLUE ) ; add ( leftPanel, BorderLayout.WEST ) ; // right final JPanel rightPanel = new JPanel () ; rightPanel.setBackground ( Color.YELLOW ) ; add ( rightPanel, BorderLayout.EAST ) ; // center final JPanel centerPanel = new JPanel ( new BorderLayout () ) ; // center top final JPanel centerTop = new JPanel () ; centerTop.setBackground ( Color.RED ) ; centerPanel.add ( centerTop, BorderLayout.NORTH ) ; // center bottom final JPanel centerBottom = new JPanel () ; centerBottom.setBackground ( Color.GREEN ) ; centerPanel.add ( centerBottom, BorderLayout.SOUTH ) ; add ( centerPanel, BorderLayout.CENTER ) ; } public static void main ( final String[] args ) { new TestFrame1 ().setVisible ( true ) ; } } BorderLayout is the layout in the container, the conditional element layout, if you need to position something else inside, put another suitable container into it and place the elements in it
Source: https://ru.stackoverflow.com/questions/68472/
All Articles