Apr 17, 2012

Border Layout


The border layout manager provides you to position components using the directions North, South, East, West, Center. The middle area is called center.
The BorderLayout class has the following constructors:

 BorderLayout()
 BorderLayout(int horizontal, int vertical)

The first one create the default Border Layout. The second allows you to create border layout with horizontal and vertical space left between components.

Border layout class have five constraints. These are used in adding components in the container.

BorderLayout.EAST
BorderLayout.WEST
BorderLayout.NORTH
BorderLayout.SOUTH
BorderLayout.CENTER

public void add(Component c, Constraint c1)

Example:

import java.awt.*;
class BorderDemo extends Frame
{
BorderDemo(String s)
        {
             super(s);
             setSize(300,140);
             add(new Button(“North”),BorderLayout.NORTH);
             add(new Button(“East”),BorderLayout.EAST);
             add(new Button(“South”),BorderLayout.SOUTH);
             add(new Button(“West”),BorderLayout..WEST);
             add(new Button(“Center”),BorderLayout.CENTER);
             setVisible(true);
        }
}
class test2
{
Public static void main(String[] args)
        {
           BorderDemo bd=new BorderDemo(“Border Layout”);
        }
}



0 comments :

Post a Comment