Copyright ©1996-1998 by Axel T. Schreiner.  All Rights Reserved.



5
Layout management

Within a Container a LayoutManager is responsible for arranging the components .

Without a LayoutManager components can be located with coordinates relative to the Container.

For FlowLayout components are added with add() and arranged by rows. The Container gets it's width either as the sum of the components or externally.

For GridLayout a table with a given number of rows and columns is constructed, where all cells have identical sizes. The components are added row after row using add(). The Container gets it's size as the sum of the rows and columns.

For BorderLayout add() takes one of four compass directions or "Center" for the remaining room in the middle and places a component there.

CardLayout is used to show one of several components alternatively. add() requires a name as a string; show() is used to call a component by name and display it.

GridBagLayout also fills a table, but for each component GridBagConstraints are specified to describe a more or less dynamic adaption of a component occupying one or more cells of the table.

This section presents examples for CardLayout and GridBagLayout and in particular permits experiments with GridBagConstraints.

[ Applet] These links permit viewing the examples as applets in a Java enabled browser.

Topics
5-1 A manager with CardLayout 205
5-2 An inspector for GridBagConstraints 210
5-3 Experiments with GridBagLayout 221

29/Apr/1998