Home Java Example Java Awt BorderLayout Example In java
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

BorderLayout Example In java

Advertisement
In this section, you will learn how to create BorderLayout in java awt package. The Border Layout is arranging and resizing components to set in five position which is used in this program. The java program uses and declares all positions as a NORTH, SOU

BorderLayout Example In java

     

Introduction

In this section, you will learn how to create BorderLayout in java awt package. The Border Layout is arranging and resizing components to set in five position which is used in this program. The java program uses and declares all positions as a  NORTH, SOUTH, WEST, EAST, and 
CENTER. Here, you will understand about this position how to use in this program.

Program Description:

Following program uses the BorderLayout class for creating Button and set on the frame. Here, define the class named BorderLayoutExample for using  this program. This Java Application uses BorderLayout for setting the position on the frame.

BorderLayout(): This is default constructors of the class Border layout class. This class constructs a new border layout without any gaps between components.  

Here is the code of this program:

import java.awt.*;
import java.awt.event.*;

public class BorderLayoutExample {

  public static void main(String[] args) {
  Frame frame= new Frame("BorderLayout Frame");
  Panel pa= new Panel();
  Button ba1= new Button();
  Button ba2=new Button();
  Button ba3=new Button();
  Button ba4=new Button();
  Button ba5=new Button();
  frame.add(pa);
  pa.setLayout(new BorderLayout());
  pa.add(new Button("Wel"), BorderLayout.NORTH);
  pa.add(new Button("Come"), BorderLayout.SOUTH);
  pa.add(new Button("Rose"), BorderLayout.EAST);
  pa.add(new Button("India"), BorderLayout.WEST);
  pa.add(new Button("RoseIndia"), BorderLayout.CENTER);
  frame.setSize(300,300);
  frame.setVisible(true);
  frame.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){
  System.exit(0);
  }
  });
  }  
}

Output this program:

Download this program.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 13, 2008

Related Tutorials

Ask Questions?    Discuss: BorderLayout Example In java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
kogee
January 10, 2013
question

how to add 2 buttons in center??
R.VIJAYAPRABHU.
March 27, 2012
IMPORTANT QUESTION

"frame.addWindowListener(new WindowAdapter()" What is the purpose of these statement?????????????
Zarana
December 10, 2012
Unnecessary Code

Following code has no meaning: I think so you have to remove it from the program. Button ba1= new Button(); Button ba2=new Button(); Button ba3=new Button(); Button ba4=new Button(); Button ba5=new Button();
DMCA.com