/* * ============================================================== * DemoGridLayout.java : Create a rectangular grid of buttons and * position them on a content pane using the grid layout manager. * * Adapted from : Pantham S., Pure JFC Swing, 1999. * Modified by : Mark Austin March, 2001 * ============================================================== */ import javax.swing.*; import java.awt.*; public class DemoGridLayout extends JApplet { Container container = null; // 1. Set grid layout parameters .... static final int iNoRows = 4; static final int iNoColumns = 3; static final int iHorizontalSpacing = 5; static final int iVerticalSpacing = 5; public void init() { // 2. Get a handle on the applet's content pane. container = this.getContentPane(); // 3. Assign the grid layout to the content pane. // parameters : rows = 3, cols = 2 // : horizontal gap = 5, vertical gap = 5 GridLayout grid = new GridLayout( iNoRows, iNoColumns, iHorizontalSpacing, iVerticalSpacing ); container.setLayout( grid ); // 4. Create and add components to the content pane. for (int i=0; i < iNoRows*iNoColumns; i = i + 1 ) container.add( new JButton( "Button " + (i+1) ) ); } }