A FlowLayout arranges widgets from left to right until there's no more space left. Then it begins a row lower and moves from left to right again. Each component in a FlowLayout gets as much space as it needs and no more. A FlowLayout is useful for laying out buttons but not for much else.

FlowLayout is the default layout for java.awt.Panel which java.applet.Applet subclasses. Therefore you don't need to do anything special to create a FlowLayout in an applet. However you do need to use the following constructors if you want to use a FlowLayout in a Window.

LayoutManagers have constructors like any other class. The constructor for a FlowLayout is

public FlowLayout()

Thus to create a new FlowLayout object you write

FlowLayout fl = new FlowLayout();

You tell an applet to use a particular LayoutManager instance by passing the object to the applet's setLayout() method like this:


Most of the time setLayout() is called in the init() method. You normally just create the LayoutManager right inside the call to setLayout() like this

this.setLayout(new FlowLayout());

Previous | Next | Top | Cafe au Lait

Copyright 1997, 1998 Elliotte Rusty Harold
Last Modified June 30, 1998