A layout manager controls how GUI components are laid out when
they are added to a container. To set the layout for a container you use
the setLayout() method, passing in an instance of the layout
manager that you want to use.
The Java API provides several layout managers some of these are:
-
FlowLayout - This lays out the components left to right, top to
bottom
-
GridLayout - This places arranges each component in a grid
pattern
-
BorderLayout - This lets you specify where to place a component
by using instructions like North, South, East, West, Center
For example to set up a Frame so that it is using a BorderLayout
manger you would use the following code:
Frame testFrame = new Frame("Test Frame"); // create a frame
testFrame.setLayout( new BorderLayout() ); // set frames layout