8.8.2 Using Flow Layout
Flow Layout is the default layout manager for every JPanel. It simply lays out components from left to right, starting new rows if necessary.
Flow Layout puts components in a row, sized at their preferred size.
If the horizontal space in the container is too small to put all the components in one row, Flow Layout uses multiple rows.
Within each row, components are centered (the default), left aligned, or right aligned as specified in the LayoutProperties of Flow Layout.
The horizontal gap and vertical gap specify the number of pixels to be put between components.
If you don't specify a gap value, Flow Layout uses 5 as the default gap value.
Using Bean Builder, the Components can be placed directly to the Container or moved around to change the position. The Vertical and Horizontal Gap can be specified using the Layout Properties Dialog.
How to use it
Create a new screen. Click on the screen and right click on it to open a pop-up menu.
Choose Flow Layout from the Layout and click on it. The components will now be arranged according to Flow Layout.
Select the Container for which the Flow Layout is set and right click on Layout Properties from the pop-up menu to open up the "Flow Layout Constraints" as shown at the bottom of the page.
Alignment (center, left and right) can be set here.
The Horizontal and Vertical gap can also be set here (by default it is 5).
A flow layout lets each component assume its natural size. So resizing can be done for this layout.
Resizing in FlowLayout
The components can be directly resized by dragging it using mouse and also by setting bounds in property sheet. Components can be resized to its minimum size and not below it. If the bounds set are less than the minimum size it reverts back to its minimum size.
The layoutProperties in FlowLayout allows us to set the HGap , VGap and alignment properties.
HGap - horizontal spacing between components.
VGap - vertical spacing between components.
Alignments - Align all the components in center, left or right side of the container screen.
Aligning Beans in FlowLayout
The beans in this layout are aligned one after the other in a sequential order. The alignment and spacing properties like RightAlign, Leftalign, TopAlign, VerticalSpacing, etc. are not applicable for this layout. Therefore in this layout, only two options are enabled when you right click on the multiple selected beans. They are Same Width and Same Height. Using these options you can you can fix the same width or height for a set of beans.