Usage

The GridLayout class is a Layout Manager which can be used to arrange controls in a container.  GridLayouts have a specified number of rows and columns.

Package

Java.awt

Subclass of

java.lang.Object
java.awt.FlowLayout implements LayoutManager, Serializable

Common Constructors

GridLayout (int Rows, int Columns)
Creates a GridLayout instance with the specified number of rows and columns.

Example

Code:

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

public class Grid1 extends Applet {
  LayoutManager Layout;
  Button [] Buttons;

  public Grid1 () {
    int i;
    
    Layout = new GridLayout (3, 2);
    setLayout (Layout);
    
    Buttons = new Button [5];
    for (i = 0; i < 5; ++i) {
      Buttons[i] = new Button ();
      Buttons[i].setLabel ("Button " + (i + 1));
      add (Buttons[i]);
    }
  }

}

See Also

Borderlayout Boxlayout Flowlayout

External Links

Sun Microsystem GridLayout Class API Version 1.6.0
Sun Microsystem GridLayout Class API Version 1.5.0
Sun Microsystem GridLayout Class API Version 1.4.2
Sun Microsystem GridLayout Class API Version 1.3.1

Site Icon Copyright © 1999-2008, jhyoung, revised 4/28/08