You are here:   HomeJava ProgrammingSwingMouseListener in Java Swing Example
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)

where,

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");
        setSize(500,500);
        setVisible(true);
        setLayout(new FlowLayout());
        add(BtnClckIt);
        setBackground(Color.BLUE);
      }
        public static void main(String[] args)
         {
           WithoutExplicitContentPane frame =new  WithoutExplicitContentPane();
         }
  }




Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes 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.



What's New and Popular





Popular Article