by Dinesh Thakur Category: AWT and Applets

The FlowLayout is one the most popular and simplest layout manager. It places components in a container from left to right in the order in which they were added to the container. When one row is filled, layout advances to the next row. It is analogous to lines of text in a paragraph. Components managed by a FlowLayout are always set to their preferred size (both width and height) regardless of the size of the parent container. Whenever the container is resized then the components in the container are also adjusted from the top-left comer. The FlowLayout is the default layout manager for a Panel, Applet and JPanel.

The java.awt.FlowLayout class contain the following constructors and methods:



FlowLayout ()

Creates a default FlowLayout manager: centered alignment, horizontal spacing and 5 vertical units.

FlowLayout (int)

Creates a FlowLayout manager with alignment and given horizontal and vertical spacing of 5 units.

FlowLayout (int, int, int)

Creates a FlowLayout manager with alignment, horizontal and vertical spacing data.

getAlignment ()

Gets the alignment of this layout.

getHgap ()

Gets the horizontal spacing.

getVgap ()

Gets the vertical spacing.

setAlignment (int)

Specifies the alignment of this layout.

setHgap (int)

Specifies the horizontal spacing.

setVgap (int)

Specifies the vertical spacing.


Also has the constant-FlowLayout.LEFT, and FlowLayout.CENTER FlowLayout.RIGHT who can be used to specify or determine the alignment of this layout manager.

import java.awt.*;

class FlowLayoutExample extends Frame
         Button[] button =new Button[10];
         setLayout(new FlowLayout());
         for(int i=0;i<button.length;i++)
                  button[i]=new Button("Button "+(i+1));
  class FlowLayoutJavaExample
       public static void main(String args[])
             FlowLayoutExample frame = new FlowLayoutExample();
             frame.setTitle("FlowLayout in Java Example");

FlowLayout in Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles