Home Java Example Java Awt BorderLayout Example In java



BorderLayout Example In java
Posted on: March 13, 2008 at 12:00 AM
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.

Related Tags for BorderLayout Example In java:
javaccomclasslayoutapplicationscriptbuttoniocomponentssedipordercomponentawtnameusingborderthispackagesetpositionappresizingcreatecenterdefineframetexforexampleprogramtolearnramexamposastdescriptioneareilitdessectionliuseceenterinnoasstamntoutsizingososicaosiosjpackclesdeclareallagenamedmehowproppackcatcreatingxawhichxampssoginatpackisllivmplerlerlfolloweaandarrtsettingwingwtvausesttzscrssririprdthsouthavstabatiapeclesifinframesiicaicapleplprndonomogrolonor


More Tutorials from this section

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

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.