About FlowLayout

FlowLayout arranges components in rows from left to right, and then top to bottom using each component's preferredSize . FlowLayout lines up as many components as it can in a row, then moves to a new row. Typically, FlowLayout is used to arrange buttons on a panel.

FlowLayout image

Note: If you want a panel that arranges the components vertically, rather than horizontally, see VerticalFlowLayout.

You can choose how to arrange the components in the rows of a FlowLayout container by specifying an alignment justification of left, right, or center. You can also specify the amount of gap (horizontal and vertical spacing) between components and rows. Use the Inspector to change both the alignment and gap properties when you're in the Java Visual Editor.

Alignment

Gap

The default gap between components in a FlowLayout is 5 pixels.

To change the horizontal or vertical gap, select the FlowLayout object in the Structure window, then modify the pixel value of the hgap (horizontal gap) or vgap (vertical gap) property in the Inspector.

Order of Components

To change the order of the components in a FlowLayout container, drag the component to the new location, or right-click a component and choose Move to First or Move to Last.