CSc 2700: Lecture # 7
Border Layout
September 18, 2008
1
Introduction
To add components to a frame, Java provides layout managers. Each layout
manager is an object that determines how components are placed in a frame.
Different layout managers arrange widgets differently. In this lecture we will
discuss the border layout manager. In subsequent lectures, we will discuss
additional layout managers.
2
Border Layout
BorderLayout is the default layout manager for JFrame. If you do not in-
stantiate a layout manager for a frame, components are placed in a frame
using the BorderLayout layout manager. The BorderLayout manager divides
a frame into five areas: NORTH, WEST, SOUTH, EAST, and CENTER.
The BorderLayout constructors are:
Figure 1: BorderLayout
1
This
preview
has intentionally blurred sections.
Sign up to view the full version.
BorderLayout()
BorderLayout(int horizGap, int vertGap)
where horizGap and vertGap specify horizontal and vertical space, in pixels,
between components. The method
add(Component c, int region)
places a component into a container. The parameter region is specified by
one of the constants
BorderLayout.NORTH,
BorderLayout.SOUTH,
BorderLayout.EAST,
BorderLayout.WEST, or
BorderLayout.CENTER
If no region is specified, a component is placed in the center region. Only
one component can be placed in a region and components are resized to fit
the region. A button is a member of the JButton class. Three constructors

This is the end of the preview.
Sign up
to
access the rest of the document.
- Spring '08
- Duncan
- new JButton, Layout manager
-
Click to edit the document details