FlowLayout

The FlowLayout manager is the default Layout Manager for Applets and Panels. It is the most basic of the layout managers. It places components, left to right, within the container. If it runs out of room on one "line," it wraps around to the next line.

The only additional control that may be specified is the horizontal orientation -- LEFT, RIGHT, and CENTER (the default) -- and horizontal and vertical gap values. For details, see the class constructors.

Below is code for a basic Flow Layout:

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

public class step1 extends Applet{

// Illustrates Flow Layout

MyFrame outerBox;

Button button1;
Button button2;
Button button3;
Button button4;
Button button5;
Button button6;

  public void init ( ){

    outerBox = new MyFrame ( );
    outerBox.addWindowListener ( outerBox );

    button1 = new Button ( "Button 1" );
    button2 = new Button ( "Button 2" );
    button3 = new Button ( "Button 3" );
    button4 = new Button ( "Button 4" );
    button5 = new Button ( "Button 5" );
    button6 = new Button ( "Button 6" );

    button1.setBackground ( Color.red );
    button2.setBackground ( Color.lightGray );
    button3.setBackground ( Color.cyan );
    button4.setBackground ( Color.yellow );
    button5.setBackground ( Color.green );
    button6.setBackground ( Color.orange );

    outerBox.setLayout ( new FlowLayout ( ) );
    outerBox.setBackground ( Color.white );
    outerBox. setFont (new Font ("Helvetica", Font.PLAIN, 18) );
    outerBox.resize (600, 500);

    outerBox.add ( button1 );
    outerBox.add ( button2 );
    outerBox.add ( button3 );
    outerBox.add ( button4 );
    outerBox.add ( button5 );
    outerBox.add ( button6 );

    outerBox.show( );

  } // end init

}// end step1

Run the applet