FileDocCategorySizeDatePackage
GridBag5.javaAPI DocExample717Wed Aug 27 03:00:26 BST 1997None

GridBag5.java

import java.awt.*;

public class GridBag5 extends java.applet.Applet {

	GridBagConstraints constraints = new GridBagConstraints();

	void addGB( Component component, int x, int y  ) {
		constraints.gridx = x;  constraints.gridy = y;
		add ( component, constraints );
	}
	
	public void init() {
		setLayout( new GridBagLayout() );
		int x, y;  // for clarity
		addGB( new Button("North"),	 x=1,y=0 );

		constraints.ipadx = 25;  // set padding
		constraints.ipady = 25;
		addGB( new Button("West"), 	 x=0,y=1 );
		constraints.ipadx = 0;   // set padding back
		constraints.ipady = 0;

		addGB( new Button("Center"), x=1,y=1 );
		addGB( new Button("East"), 	 x=2,y=1 );
		addGB( new Button("South"),  x=1,y=2 );
	}
}