All About Class BorderLayout in Java

This layout manager has the concept of four border regions and a center area. When we add() something using BorderLayout,we need to call add() that takes a String object as first argument and that String must specify with proper capitalization. So, 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{
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)
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();

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");
BorderLayout relies on position string, being case sensitive passing "NORTH" or "north" instead of "North" will not work. Foe every placement but "Center", the element that we add is compressed to fit in the smallest amount of space along one dimension while it is stretched to the minimum along the other dimension. "Center" however spreads out along both dimensions to occupy the middle.
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.