Thursday, July 8, 2010

Border Layout  

0 comments

BorderLayout divides the container into five Geographical regions namely
North,South,East,West and Center.This is very commonly used Lyout
Manager.You can add at most one component to each region of a BorderLayout.
To put more than one component in a section, put them in a JPanel (with its own layout),
then add that panel to the border layout.
When you add components to a container which uses BorderLayout, specify the target region as the second parameter as, for example, BorderLayout.SOUTH.
If nothing is added to a region then neighbouring regions go on to fill up space.



Construcors:-
new BorderLayout();
new BorderLayout(int hgap,int vgap);

Example
Source Code:-
import javax.swing.*;
import java.awt.*;

class borderlayout extends JFrame{
public static void main(String a[]){
//initializing frames
JFrame jf=new JFrame("BorderLayout");
JFrame jf1=new JFrame("BorderLayout");
//initializing panels
JPanel panel=new JPanel();
//initializing buttons
JButton jbn=new JButton("North");
JButton jbs=new JButton("South");
JButton jbe=new JButton("East");
JButton jbw=new JButton("West");
JButton jbc=new JButton("Central");
//setting up layout
panel.setLayout(new BorderLayout());
panel.add(jbn,BorderLayout.NORTH);
panel.add(jbs,BorderLayout.SOUTH);
panel.add(jbe,BorderLayout.EAST);
panel.add(jbw,BorderLayout.WEST);
panel.add(jbc,BorderLayout.CENTER);
//adding to frame
jf.getContentPane().add(panel);
jf.setSize(250,200);
jf.setVisible(true);
}
}

What next?

You can also bookmark this post using your favorite bookmarking service:

Related Posts by Categories



0 comments: to “ Border Layout

Extension Factory Builder