Saturday, February 21, 2009

Border Layout

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);
}
}


Other Layout Managers Links :-

Layout Manager Basics
Box Layout
Grid Layout
Flow Layout
Card Layout
GridBag Layout

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP