A GridLayout places each component into a cell of one size. Thus all components have the same size. A GridbagLayout allows components to span multiple cells. Therefore components can have different sizes. There are other differences, but that's the main one.
import java.applet.Applet;
import java.awt.Button;
import java.awt.FlowLayout;
public class TapeDeck extends Applet {
public void init() {
setLayout(new FlowLayout(FlowLayout.CENTER, 5, 10));
add( new Button("Play"));
add( new Button("Rewind"));
add( new Button("Fast Forward"));
add( new Button("Pause"));
add( new Button("Stop"));
}
}
import java.applet.Applet;
import java.awt.Label;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.GridLayout;
public class PaymentMethod extends Applet {
public void init() {
setLayout(new GridLayout(6, 1));
add(new Label("How will you pay for your pizza?"));
CheckboxGroup cbg = new CheckboxGroup();
add(new Checkbox("Visa", cbg, false));
add(new Checkbox("MasterCard", cbg, false));
add(new Checkbox("American Express", cbg, false));
add(new Checkbox("Discover", cbg, true));
add(new Checkbox("Cash", cbg, true));
}
}