Border Layout
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 BasicsBox Layout
Grid Layout
Flow Layout
Card Layout
GridBag Layout


















0 comments:
Post a Comment
Post a Comment