Layout in a Container

Figure 22-5 shows a frame to which we have added several controls. They are positioned automatically as we add them.

Figure 22-5. Arranging controls on the screen

image

The code for this is on the CD in the directory containing all the other AWT programming material. The problem is the end result doesn't look very professional because nothing is neatly aligned. Solution: layout managers!

Layout Managers are classes that specify how components should be placed in a container. You choose a layout manager for a container with a call similar to the following invoked on the content pane:

setLayout( new FlowLayout() );

We'll look ...

Get Just Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.