Java Reference
In-Depth Information
LISTING 7.21
continued
DISPLAY
In the BorderPanel class constructor, the layout manager of the panel is explic-
itly set to be border layout. The buttons are then created and added to specific
panel areas. By default, each button is made wide enough to accommodate its
label and tall enough to fill the area to which it has been assigned. As the frame
(and the panel) is resized, the size of each button adjusts as needed, with the but-
ton in the Center area filling any unused space.
Each area in a border layout displays only one component. That is, only one
component is added to each area of a given border layout. A common error is to
add two components to a particular area of a border layout, in which case the first
component added is replaced by the second, and only the second is seen when the
container is displayed. To add multiple components to an area within a border
layout, we first add the components to another container, such as a JPanel , then
add the panel to the area.
Search WWH ::




Custom Search