Previous | Next | Trail Map | Creating a GUI with JFC/Swing | Contents

Laying Out Components Within a Container

This lesson tells you how to use all the layout managers the Java platform provides. It also tells you how to use absolute positioning (no layout manager) and gives an example of writing a custom layout manager. For each layout manager (or lack thereof), this section has an example that can run either as an applet or as an application. By resizing the window the example brings up, you can see how size changes affect the layout.

Before reading this section, you should understand basic layout management concepts, which you can find in Layout Management(in the Creating a User Interface trail).


Note: This lesson assumes you're using the Swing components. If you're using the AWT components instead, then you should read the old version of this lesson, which is available by download as part of the Creating a User Interface (AWT Only) archive.

Using Layout Managers

This section gives both general rules and detailed instructions on using each of the layout managers that the Java platform provides.

Creating a Custom Layout Manager

Instead of using one of the Java platform's layout managers, you can write your own. Layout managers must implement the LayoutManager 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. Absolute positioning is inappropriate for many programs, since the size of components can be different on different systems. [PENDING: check]

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.


Previous | Next | Trail Map | Creating a GUI with JFC/Swing | Contents