FileDocCategorySizeDatePackage
gridbag.javaAPI DocExample2596Mon Mar 24 01:57:24 GMT 1997None

gridbag

public class gridbag extends Applet

Fields Summary
Constructors Summary
Methods Summary
public static voidaddComponent(java.awt.Container container, java.awt.Component component, int gridx, int gridy, int gridwidth, int gridheight, int fill, int anchor)

        LayoutManager lm = container.getLayout();
        if (!(lm instanceof GridBagLayout)) {
            throw new AWTException ("Invalid layout" + lm);
        } else {
            GridBagConstraints gbc = new GridBagConstraints ();
            gbc.gridx = gridx;
            gbc.gridy = gridy;
            gbc.gridwidth = gridwidth;
            gbc.gridheight = gridheight;
            gbc.fill = fill;
            gbc.anchor = anchor;
            ((GridBagLayout)lm).setConstraints(component, gbc);
            container.add (component);
        }
    
public voidinit()

	Button b;
        GridBagLayout gb = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        setLayout(gb);
	try {
/* Row One - Three button */
            b = new Button ("One");
            addComponent (this, b, 0, 0, 1, 1, 
                GridBagConstraints.BOTH, GridBagConstraints.CENTER);
            b = new Button ("Two");
            addComponent (this, b, 1, 0, 1, 1, 
                GridBagConstraints.BOTH, GridBagConstraints.CENTER);
            b = new Button ("Three");
            addComponent (this, b, 2, 0, 1, 1, 
                GridBagConstraints.BOTH, GridBagConstraints.CENTER);

/* Row Two - Two buttons */
            b = new Button ("Four");
            addComponent (this, b, 0, 1, 2, 1, 
                GridBagConstraints.BOTH, GridBagConstraints.CENTER);
            b = new Button ("Five");
            addComponent (this, b, 2, 1, 1, 2,
                GridBagConstraints.BOTH, GridBagConstraints.CENTER);

/* Row Three - Two buttons */

            b = new Button ("Six");
            addComponent (this, b, 0, 2, 1, 1, 
                GridBagConstraints.BOTH, GridBagConstraints.CENTER);
            b = new Button ("Seven");
            addComponent (this, b, 1, 2, 1, 1, 
                GridBagConstraints.BOTH, GridBagConstraints.CENTER);
        } catch (Exception e) {
            e.printStackTrace();
        }