All About Class BorderLayout in Java



BorderLayout manager implements a common layout style which has five zones.Each of these zones is named with a String like North,South,East,West and Center.A BorderLayout lays outs a container to contain number of GUI elements like buttons,labels,grids,texts etc.

The structure of the class BorderLayout is given as:



public class java.awt.BorderLayout extends java.lang.Objects implements java.awt.LayoutManager{
//constructors
public BorderLayout();//default constructor ,constructs a new border layout.
public BorderLayout(int hgap,int vgap);
//creates a new border layout with the specified horizontal and vertical gaps. The specified 
//space between the components(gaps)
//method
public void addLayoutComponent(String name,Component comp);
public void layoutContainer(Container target);
public Dimension minimumLayoutSize(Container target);
public Dimension preferredLayoutSize(Container target);
public void removeLayoutSize(Container target);
public String toString();
}
 
Example

Frame frame=new Frame();
frame.setLayout(new BorderLayout(20,40));
Button buttonN,buttonS,buttonE,buttonW,buttonC;
buttonN=new Button("North");
buttonS=new Button("South");
buttonW=new Button("West");
buttonE=new Button("East");
buttonC=new Button("Center");
frame.add("North",buttonN);
frame.add("South",buttonS);
frame.add("West",buttonW);
frame.add("East",buttonE);
frame.add("Center",buttonC);
}
 
BorderLayout relies on position string,being case sensitive passing "NORTH" or "north" instead of "North" will not work.
All About Class BorderLayout in Java All About Class BorderLayout in Java Reviewed by Animesh Chatterjee on October 22, 2018 Rating: 5

No comments:

Powered by Blogger.