You can use the visual editor for Java to layout a class using
GridLayout.
The layout manager java.awt.GridLayout lays out components in a grid
of equal-sized rectangles in rows and columns. You can set the number of rows
and columns that a GridLayout will contain. As components are added, they
are added in order based on the componentOrientation: right to left, or left
to right.
- To set the grid dimensions for a GridLayout:
- In the Design view or Java Beans view, select the component
that is using GridLayout.
- Click the Customize Layout
toolbar
button. The Customize Layout dialog opens.
- On the Layout notebook tab, enter a value for either Number
of columns or Number of rows.
If you set both the number of rows and the number of columns to non-zero
values, the number of columns specified is ignored. Instead, the number of
columns is determined from the specified number or rows and the
total number of components in the layout. So, for example, if you specify
three rows and two columns, and you add nine components to the layout, they
will be displayed as three rows of three columns. Specifying the number of
columns affects the layout only when the number of rows is set to zero.
- To add a component to a GridLayout:
- Select a Swing/AWT component on the palette.
- Move your cursor over the Design view and click on the GridLayout.
- To move a component within a GridLayout:
- On the Design view, click and drag the component that you are
moving. As you move your cursor, a black bar will indicate
the position where the component will be added.
- Release your mouse to move the component.
- To set spacing for components with a GridLayout:
- In the Design view or Java Beans view, select the component
that is using GridLayout.
- Click the Customize Layout
toolbar
button. The Customize Layout dialog opens.
- On the Layout notebook tab, enter values for Horizontal
gap and Vertical gap. Horizontal gap sets
the distance in pixels between columns, while vertical gap sets the spacing
between rows.