12.2. The BorderLayout Manager

BorderLayout divides the window into five sections: NORTH, SOUTH, EAST, WEST, and CENTER. You add a component to a region by using a version of the add method that takes two arguments instead of the normal one. The first argument is the component, and the second argument is a string naming the region that should hold the component, as follows:

add(buttonForTop, BorderLayout.NORTH);
add(scrollbarForRightSide, BorderLayout.EAST);
add(panelForRemainingSpace, BorderLayout.CENTER);

The role of the layout manager is to provide sizes and positions for the components. Components added to NORTH or SOUTH are resized to their preferred height, with a width equal to the Container, and then placed at the top or bottom of the ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.