Illustration of Nested GridLayout


Here are several versions of the same applet displayed in different sized areas. Note how we use a nested GridLayout to arrange the Components.



Here the width is 250 and the height is 100

Here the width is 150 and the height is 250


Here is the code for the applet


import java.awt.*;

public class GridNested extends java.applet.Applet
{
    public void init()
    {
        setLayout(new GridLayout(1,2,5,5));
        add(new Button("One"));
        Panel p = new Panel();
        p.setLayout(new GridLayout(3,1,5,5));
        Panel newp = new Panel();
        newp.add(new Label("Two"));
        p.add(newp);
        newp = new Panel();
        newp.add(new Button("Longer Name"));
        p.add(newp);
        newp = new Panel();
        newp.add(new Label("Three"));
        p.add(newp);
        add(p);
    }

}