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

alt text

    2 answers 2

    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

      • I can post. The chip in this sho is stretched. You just need Schaub Left blocked Tor, and not vice versa! - Torteg 4:21 pm
      • one
        use as a main FlowLayout, place a separate leyout or frame first, a second BorderLayout (in it, if necessary, do not use, left and right edges), well, 3m is another frame, it will turn out like you in the figure - Gorets