by Dinesh Thakur Category: Swing

The flow layout manager is the simplest of all the layout managers. It positions the components in the order they are added to the container. It places the components from left to right, that is, horizontally. Once a row gets completely filled with components then the remaining components are placed in the next row. It is the default layout manager for Applet and Panel. Each component is evenly separated from its neighboring components by leaving a small space not only from above and below it, but also from left and right.

The flow layout manager can be created by using any of the following constructors.

FlowLayout ()

FlowLayout (int alignment)

FlowLayout (int alignment, int hor, int ver)


alignment specifies the alignment of laid out components. It can take one of these constants-FlowLayout.LEFT, FlowLayout.RIGHT, and FlowLayout.CENTER

hor and ver specify the horizontal and vertical space left between each component, respectively


import java.awt.*;

import javax.swing.*;
public class WithoutExplicitContentPane extends JFrame
    private final int SIZE = 100;
    private JButton BtnClckIt = new JButton("Click It");
    public WithoutExplicitContentPane()
        super("ContentPane with FlowLayout in Java Swing Example");
        setLayout(new FlowLayout());
        public static void main(String[] args)
           WithoutExplicitContentPane frame =new  WithoutExplicitContentPane();

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