Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information

Java Cup Logo

JDC Home Page


Top
Back
Next
Online Training
shadowSearchFAQFeedback

FlowLayout

The FlowLayout arranges Component objects left-to-right until no more objects fit on that line. Any further objects you add will wrap to the next line. Each line of Component objects is centered in the Container. FlowLayout is the default behavior of Panel and, therefore, of Applet.

The applet invocation in HTML is:

<applet code=FlowLayoutTest.class CODEBASE="/applets/magelang/AWT-Training/Examples/"
width=150 height=35>
</applet>

results in applet:



The same applet can be invoked with a different geometry--the layout manager takes care of placing the elements within the region:

<applet code=FlowLayoutTest.class CODEBASE="/applets/magelang/AWT-Training/Examples/"
width=50 height=90>
</applet>

results in applet:



Corresponding source code:

import java.awt.*;
import java.applet.Applet;

public class FlowLayoutTest extends Applet {
    public void init() {
        setLayout(new FlowLayout()); // default
        add(new Button("B1"));
        add(new Button("B2"));
        add(new Button("B3"));
    }
}

See also How to Use FlowLayout.

Related exercise(s):