FlowLayout
FlowLayout arranges components in rows from left to right, and then top to bottom using the each component's natural, 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.
Example
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.
- The default alignment in a FlowLayout is Center.
- Center alignment places the first component in the center of the first row of the panel . As you add components, FlowLayout spreads them outward until you have no more room on the first line. Then it starts a new row.
- Left alignment fills the container from left to right.
- Right alignment fills the container from right to left.
- The default gap between components in a FlowLayout is 5 pixels.
You can change the alignment and gap properties from the Component Inspector when you're using the UI Designer.
- To change the alignment, select the flowLayout object in the Component Tree, then specify a value in the Inspector for the alignment property as follows:
0=LEFT
1=CENTER
2=RIGHT
- To change the horizontal or vertical gap, select the FlowLayout object in the Component Tree, then modify the pixel value of the hgap (horizontal gap) or vgap (vertical gap) property in the Inspector.
- 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.