Contents |
[PENDING: introduce layout managers; point to Layout Management.]A layout manager is an object that controls the size and position of components in a container. Layout managers adhere to the
LayoutManager
interface. By default, everyContainer
object has aLayoutManager
object that controls its layout. ForJPanel
objects, the default layout manager is an instance of theFlowLayout
class. For aJFrame
's content pane, the default layout manager is an instance of theBorderLayout
class.This lesson has examples of every kind of layout manager. each example can run either as an applet or as an application. The examples bring up windows that you can resize to see how resizing affects the layout.
Using Layout Managers
Here's where to learn how to use layout managers. This section gives both general rules and detailed instructions on using each of the layout managers that the AWT provides.Creating a Custom Layout Manager
Instead of using one of the AWT's layout managers, you can write your own. Layout managers must implement theLayoutManager
interface, which specifies the five methods every layout manager must define.Doing Without a Layout Manager (Absolute Positioning)
You can position components without using a layout manager. Generally, this solution is used to specify absolute positions for components, and only for programs that are executed on only one platform or that use custom components. Absolute positioning is often unsuitable for platform-independent programs, since the size of components can be different on different platforms.Solving Common Layout Problems
Some of the most common layout problems are that components are displayed too small -- or not at all. This section tells you how to fix these and other common layout problems.
Contents |