Java Reference
In-Depth Information
In Java, you build up user interfaces by adding components into containers such as
panels. Each container has its own layout manager, which determines how the
components are laid out.
Each container has a layout manager that directs the arrangement of its
components.
By default, a JPanel uses a flow layout. A flow layout simply arranges its
components from left to right and starts a new row when there is no more room in the
current row.
Three useful layout managers are the border layout, flow layout, and grid layout.
Another commonly used layout manager is the border layout. The border layout
groups the container into five areas: center, north, west, south, and east (see Figure 1 ).
Not all of the areas need to be occupied.
When adding a component to a container with the border layout, specify the
NORTH , EAST , SOUTH , WEST , or CENTER position.
The border layout is the default layout manager for a frame (or, more technically, the
frame's content pane). But you can also use the border layout in a panel:
panel.setLayout(new BorderLayout());
Now the panel is controlled by a border layout, not the flow layout. When adding a
component, you specify the position, like this:
panel.add(component, BorderLayout.NORTH);
788
Search WWH ::




Custom Search