Showing posts with label Flow Layout in java. Show all posts
Showing posts with label Flow Layout in java. Show all posts

Wednesday, 12 June 2019

Layout Manger in java | Flow Layout in java - Online Help

Layout manager:

A layout manager is a special object that determines how the components of a container are organized. The layout manager is an instance of any class that implements the layout manager interface. The layout manager is set by the setLayout() method. The general format is:

void setLayout(LayoutManager obj)

Types of layout managers:

The various layout manager is as follows:
1.Flow Layout
2.Border Layout
3.Grid Layout
4.Card Layout

Flow Layout in java:

 Flow layout is the default layout manager for an applet. The FlowLayout class places the controls in a row that is centered in the available space. If the controls cannot fit in the current row, another row is started.

The FlowLayout class has three constructors. They are:

1.FlowLayout()
2.FlowLayout(int alignment)
3.FlowLayout(int alignment,int h,int v)

Parameter
Alignment-specifies how each line is aligned. The valid values are alignment. They are:
FlowLayout.LEFT
FlowLayout.RIGHT
FlowLayout.CENTER

h-specifies the horizontal or gap between controls.

v-specifies the vertical gap between controls.

Sample program:

import java.awt.*;
import java.aplet.*;
public class FlowLayoutDemo extends Applet
{
public void init()
{
setLayout(new FlowLayout(FlowLayout.RIGHT,5,5));
for(int i=1;i<12;i++)
{
add(new Button("toys"+i);
}
}
}