The class BorderLayout arranges the components to fit in the five regions: east, west, north, south and center.
Border Layout
The class BorderLayout arranges the components to fit in the five regions: east, west, north, south and center. Each region is can contain only one component and each component in each region is identified by the corresponding constant NORTH, SOUTH, EAST, WEST, and CENTER.
constructors
- BorderLayout():Constructs a new border layout with no gaps between components.
- BorderLayout(int hgap, int vgap):Constructs a border layout with the specified gaps between components.
methods:
- void removeLayoutComponent(Component comp) :Removes the specified component from this border layout.
- void setHgap(int hgap) :Sets the horizontal gap between components.
- void setVgap(int vgap) :Sets the vertical gap between components.
- void addLayoutComponent(String name, Component comp) :If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.
- int getHgap() :Returns the horizontal gap between components.
- float getLayoutAlignmentX(Container parent) :Returns the alignment along the x axis.
- float getLayoutAlignmentY(Container parent) :Returns the alignment along the y axis.
- int getVgap() :Returns the vertical gap between components
sample program
import java.awt.*;
import java.awt.event.*;
public class BorderLayoutExample
{
public static void main(String[] args)
{
Frame frame= new Frame("BorderLayout Frame");
Panel pa= new Panel();
Button ba1= new Button();
Button ba2=new Button();
Button ba3=new Button();
Button ba4=new Button();
Button ba5=new Button();
frame.add(pa);
pa.setLayout(new BorderLayout());
pa.add(new Button("Wel"), BorderLayout.NORTH);
pa.add(new Button("Come"), BorderLayout.SOUTH);
pa.add(new Button("Rose"), BorderLayout.EAST);
pa.add(new Button("India"), BorderLayout.WEST);
pa.add(new Button("RoseIndia"), BorderLayout.CENTER);
frame.setSize(300,300);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
output
No comments :
Post a Comment