All About Class FlowLayout in AWT in Java

The most basic and default layout in java is FlowLayout. The manager implements a simple Layout style which is similar to how words flow in a text editor.Components are laid from upper left corner,left to right and top to bottom.When no more components fit on a line,the next one will appear in the next line.A small space is left between components,above and below.However user can change this gap,alignment etc.The default gap is five pixels and default alignment is center.Below are the different functions for FlowLayout.FlowLayout is typically used to arrange buttons in a panel.
The class structure of class FlowLayout is given as:


public class java.awt.FlowLayout extends java.lang.Object implements java.awt.LayoutManager{
//member elements
public final static int CENTER;
//this indicates that each row of components should be at center.
public final static int LEFT;
//this indicates that each row of components should be at left justified.
public final static int RIGHT;
//this indicates that each row of components should be at right justified.
//constructor
public FlowLayout();
public FlowLayout(int alignment);//alignment can be LEFT,CENTER,RIGHT
public FlowLayout(int alignment,int hgap,int vgap));//alignment can be LEFT,CENTER,RIGHT
//hgap and vgap are the space between two components horizontally and vertically.
//methods
public void addLayoutComponent(String name,Component comp);
public void layoutContainer(Container target);
}
 
public FlowLayout();
Creates a new FlowLayout manager with a centered alignment and a default 5 pixel horizontal and vertical gap.
public FlowLayout(int alignment);
Creates a new FlowLayout manager with a centered alignment and a default 5 pixel horizontal and vertical gap.The alignment argument must be FlowLayout.LEFT,FlowLayout.RIGHT,FlowLayout.CENTER
All About Class FlowLayout in AWT in Java All About Class FlowLayout in AWT in Java Reviewed by Animesh Chatterjee on October 23, 2018 Rating: 5

No comments:

Powered by Blogger.