O'Reilly logo

PURE Java™ 2 by Kenneth Litwak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Leaving Positioning to Layout Managers

The best way to position and size components is to have a layout manager do it for you. The package java.awt contains the classes for performing the layout of GUI components on the screen and for creating, manipulating and interrogating the layout of those components. The java.awt package provides five layout managers: FlowLayout, BorderLayout, GridLayout, CardLayout, and GridBagLayout.

Note

Unlike most AWT classes, the layout manager classesinherit directly from Object rather than from java.awt.Component.

The following sections show examples of how to use each layout manager.

FlowLayout Code Example

The strategy used by the FlowLayout layout manager is to place components from left to right, top to bottom, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required