SlideShare a Scribd company logo
NADAR SARASWATHI COLLEGE OF ARTS&SCIENCE,THENI
DEPARTMENT OF COMPUTER SCIENCE&INFORMATION
TECHOLOGY
R.RAMYA DEVI
I-MSC(CS)
ADVANCED JAVA PROGRAMMING
Topic: Border Layout
LAYOUT MANAGER
Java LayoutManagers:
 The LayoutManagers are used to arrange components in a
particular manner. The Java LayoutManagers facilitates us to
control the positioning and size of the components in GUI
forms. LayoutManager is an interface that is implemented by
all the classes of layout managers. There are the following
classes that represent the layout managers:
LAYOUT MANAGER TYPES
 java.awt.BorderLayout
 java.awt.FlowLayout
 java.awt.GridLayout
 java.awt.CardLayout
 java.awt.GridBagLayout
 javax.swing.BoxLayout
 javax.swing.GroupLayout
 javax.swing.ScrollPaneLayout
 javax.swing.SpringLayout etc.
BORDER LAYOUT
Java BorderLayout:
 The BorderLayout is used to arrange the components in
five regions: north, south, east, west, and center. Each
region (area) may contain one component only. It is the
default layout of a frame or window. The BorderLayout
provides five constants for each region:
 public static final int NORTH
 public static final int SOUTH
 public static final int EAST
 public static final int WEST
 public static final int CENTER
Constructors of BorderLayout class:
 BorderLayout(): creates a border layout but with
no gaps between the components.
 BorderLayout(int hgap, int vgap): creates a
border layout with the given horizontal and vertical
gaps between the components.
EXAMPLE 1
Example of BorderLayout class: Using
BorderLayout() constructor
FileName: Border.java
import java.awt.*;
import javax.swing.*;
public class Border
{
JFrame f;
Border()
{
f = new JFrame();
// creating buttons
JButton b1 = new JButton("NORTH");
// the but on will be labeled as NORTH
JButton b2 = new JButton("SOUTH");
// the button will be labeled as SOUTH
JButton b3 = new JButton("EAST");
// the button will be labeled as EAST
JButton b4 = new JButton("WEST");
// the button will be labeled as WEST
JButton b5 = new JButton("CENTER“);
// the button will be labeled as CENTER
f.add(b1, BorderLayout.NORTH); // b1 will be placed
in the North Direction
f.add(b2, BorderLayout.SOUTH); // b2 will be placed
in the South Direction
f.add(b3, BorderLayout.EAST); // b2 will be
placed in the East Direction
f.add(b4, BorderLayout.WEST); // b2 will be
placed in the West Direction
f.add(b5, BorderLayout.CENTER); // b2 will be place
d in the Center
f.setSize(300, 300);
f.setVisible(true);
}
public static void main(String[] args)
{
new Border();
}
}
OUTPUT:
EXAMPLE 2
Example of BorderLayout class: Using
BorderLayout(int hgap, int vgap) constructor
The following example inserts horizontal and vertical
gaps between buttons using the parameterized
constructor BorderLayout(int hgap, int gap)
FileName: BorderLayoutExample.java
// import statement
import java.awt.*;
import javax.swing.*;
public class BorderLayoutExample
{
JFrame jframe;
// constructor
BorderLayoutExample()
{
// creating a Frame
jframe = new JFrame();
// create buttons
JButton btn1 = new JButton("NORTH");
JButton btn2 = new JButton("SOUTH");
JButton btn3 = new JButton("EAST");
JButton btn4 = new JButton("WEST");
JButton btn5 = new JButton("CENTER");
// creating an object of the BorderLayout class using
// the parameterized constructor where the horizontal gap is
20
// and vertical gap is 15. The gap will be evident when button
are placed
// in the frame
jframe.setLayout(new BorderLayout(20, 15));
jframe.add(btn1, BorderLayout.NORTH);
jframe.add(btn2, BorderLayout.SOUTH);
jframe.add(btn3, BorderLayout.EAST);
jframe.add(btn4, BorderLayout.WEST);
jframe.add(btn5, BorderLayout.CENTER);
jframe.setSize(300,300);
jframe.setVisible(true);
}
// main method
public static void main(String argvs[])
{
new BorderLayoutExample();
}
}
OUTPUT:
EXAMPLE 3
Java BorderLayout:
The add() method of the JFrame class can work even
when we do not specify the region. In such a case,
only the latest component added is shown in the
frame, and all the components added previously get
discarded. The latest component covers the whole
area. The following example shows the same.
FileName: BorderLayoutWithoutRegionExample.java
// import statements
import java.awt.*;
import javax.swing.*;
public class BorderLayoutWithoutRegionExample
{
JFrame jframe;
// constructor
BorderLayoutWithoutRegionExample()
{
jframe = new JFrame();
JButton btn1 = new JButton("NORTH");
JButton btn2 = new JButton("SOUTH");
JButton btn3 = new JButton("EAST");
JButton btn4 = new JButton("WEST");
JButton btn5 = new JButton("CENTER");
// horizontal gap is 7, and the vertical gap is 7
// Since region is not specified, the gaps are of no us
jframe.setLayout(new BorderLayout(7, 7));
// each button covers the whole area
// however, the btn5 is the latest button
// that is added to the frame; therefore, btn5
// is shown
jframe.add(btn1);
jframe.add(btn2);
jframe.add(btn3);
jframe.add(btn4);
jframe.add(btn5);
jframe.setSize(300,300);
jframe.setVisible(true);
}
// main method
public static void main(String argvs[])
{
new BorderLayoutWithoutRegion
Example();
}
}
OUTPUT:
ADVANCED JAVA PROGRAMME

More Related Content

PPTX
Advanced Java programming
PPTX
LAYOUT.pptx
PPTX
Advanced Java programming
PPT
Chap1 1 4
PPT
Md10 building java gu is
PPT
Chap1 1.4
PPTX
09 gui
PPTX
09 gui
Advanced Java programming
LAYOUT.pptx
Advanced Java programming
Chap1 1 4
Md10 building java gu is
Chap1 1.4
09 gui
09 gui

Similar to ADVANCED JAVA PROGRAMME (20)

PPTX
09 gui
PPTX
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
PPTX
Awt, Swing, Layout managers
PPT
Unit4 AWT, Swings & Layouts power point presentation
PPTX
PPTX
Java swing
PDF
Getting started with GUI programming in Java_1
PPT
Graphical User Interface in JAVA
PPTX
LayoutManager_Lec1.pptx
PPTX
the java swing tutorial - a part of jfc swing
PPT
Basic using of Swing in Java
PPTX
Chapter 11.3
PPT
Oop lecture9 10
PDF
Swingpre 150616004959-lva1-app6892
PPT
Swing and AWT in java
PPTX
Java Graphics Programming
PDF
Java GUI PART II
PPT
Graphical User Interface (GUI) - 1
DOC
java swing notes in easy manner for UG students
09 gui
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
Awt, Swing, Layout managers
Unit4 AWT, Swings & Layouts power point presentation
Java swing
Getting started with GUI programming in Java_1
Graphical User Interface in JAVA
LayoutManager_Lec1.pptx
the java swing tutorial - a part of jfc swing
Basic using of Swing in Java
Chapter 11.3
Oop lecture9 10
Swingpre 150616004959-lva1-app6892
Swing and AWT in java
Java Graphics Programming
Java GUI PART II
Graphical User Interface (GUI) - 1
java swing notes in easy manner for UG students
Ad

More from RRamyaDevi (6)

PPTX
Ramya ppt.pptx
PPTX
python.pptx
PPTX
cryptography .pptx
PPTX
RDos.pptx
PPTX
COMPILER DESIGN
PPTX
Data structure algorithm
Ramya ppt.pptx
python.pptx
cryptography .pptx
RDos.pptx
COMPILER DESIGN
Data structure algorithm
Ad

Recently uploaded (20)

PPTX
Institutional Correction lecture only . . .
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Insiders guide to clinical Medicine.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Institutional Correction lecture only . . .
Module 4: Burden of Disease Tutorial Slides S2 2025
Renaissance Architecture: A Journey from Faith to Humanism
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
RMMM.pdf make it easy to upload and study
Insiders guide to clinical Medicine.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Anesthesia in Laparoscopic Surgery in India
Microbial diseases, their pathogenesis and prophylaxis
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf

ADVANCED JAVA PROGRAMME

  • 1. NADAR SARASWATHI COLLEGE OF ARTS&SCIENCE,THENI DEPARTMENT OF COMPUTER SCIENCE&INFORMATION TECHOLOGY R.RAMYA DEVI I-MSC(CS)
  • 3. LAYOUT MANAGER Java LayoutManagers:  The LayoutManagers are used to arrange components in a particular manner. The Java LayoutManagers facilitates us to control the positioning and size of the components in GUI forms. LayoutManager is an interface that is implemented by all the classes of layout managers. There are the following classes that represent the layout managers:
  • 4. LAYOUT MANAGER TYPES  java.awt.BorderLayout  java.awt.FlowLayout  java.awt.GridLayout  java.awt.CardLayout  java.awt.GridBagLayout  javax.swing.BoxLayout  javax.swing.GroupLayout  javax.swing.ScrollPaneLayout  javax.swing.SpringLayout etc.
  • 5. BORDER LAYOUT Java BorderLayout:  The BorderLayout is used to arrange the components in five regions: north, south, east, west, and center. Each region (area) may contain one component only. It is the default layout of a frame or window. The BorderLayout provides five constants for each region:  public static final int NORTH  public static final int SOUTH  public static final int EAST  public static final int WEST  public static final int CENTER
  • 6. Constructors of BorderLayout class:  BorderLayout(): creates a border layout but with no gaps between the components.  BorderLayout(int hgap, int vgap): creates a border layout with the given horizontal and vertical gaps between the components.
  • 7. EXAMPLE 1 Example of BorderLayout class: Using BorderLayout() constructor FileName: Border.java import java.awt.*; import javax.swing.*; public class Border { JFrame f; Border() { f = new JFrame();
  • 8. // creating buttons JButton b1 = new JButton("NORTH"); // the but on will be labeled as NORTH JButton b2 = new JButton("SOUTH"); // the button will be labeled as SOUTH JButton b3 = new JButton("EAST"); // the button will be labeled as EAST JButton b4 = new JButton("WEST"); // the button will be labeled as WEST JButton b5 = new JButton("CENTER“); // the button will be labeled as CENTER
  • 9. f.add(b1, BorderLayout.NORTH); // b1 will be placed in the North Direction f.add(b2, BorderLayout.SOUTH); // b2 will be placed in the South Direction f.add(b3, BorderLayout.EAST); // b2 will be placed in the East Direction f.add(b4, BorderLayout.WEST); // b2 will be placed in the West Direction f.add(b5, BorderLayout.CENTER); // b2 will be place d in the Center
  • 10. f.setSize(300, 300); f.setVisible(true); } public static void main(String[] args) { new Border(); } }
  • 12. EXAMPLE 2 Example of BorderLayout class: Using BorderLayout(int hgap, int vgap) constructor The following example inserts horizontal and vertical gaps between buttons using the parameterized constructor BorderLayout(int hgap, int gap) FileName: BorderLayoutExample.java
  • 13. // import statement import java.awt.*; import javax.swing.*; public class BorderLayoutExample { JFrame jframe; // constructor BorderLayoutExample() {
  • 14. // creating a Frame jframe = new JFrame(); // create buttons JButton btn1 = new JButton("NORTH"); JButton btn2 = new JButton("SOUTH"); JButton btn3 = new JButton("EAST"); JButton btn4 = new JButton("WEST"); JButton btn5 = new JButton("CENTER");
  • 15. // creating an object of the BorderLayout class using // the parameterized constructor where the horizontal gap is 20 // and vertical gap is 15. The gap will be evident when button are placed // in the frame jframe.setLayout(new BorderLayout(20, 15)); jframe.add(btn1, BorderLayout.NORTH); jframe.add(btn2, BorderLayout.SOUTH); jframe.add(btn3, BorderLayout.EAST); jframe.add(btn4, BorderLayout.WEST); jframe.add(btn5, BorderLayout.CENTER); jframe.setSize(300,300); jframe.setVisible(true); }
  • 16. // main method public static void main(String argvs[]) { new BorderLayoutExample(); } }
  • 18. EXAMPLE 3 Java BorderLayout: The add() method of the JFrame class can work even when we do not specify the region. In such a case, only the latest component added is shown in the frame, and all the components added previously get discarded. The latest component covers the whole area. The following example shows the same. FileName: BorderLayoutWithoutRegionExample.java
  • 19. // import statements import java.awt.*; import javax.swing.*; public class BorderLayoutWithoutRegionExample { JFrame jframe; // constructor BorderLayoutWithoutRegionExample() {
  • 20. jframe = new JFrame(); JButton btn1 = new JButton("NORTH"); JButton btn2 = new JButton("SOUTH"); JButton btn3 = new JButton("EAST"); JButton btn4 = new JButton("WEST"); JButton btn5 = new JButton("CENTER"); // horizontal gap is 7, and the vertical gap is 7 // Since region is not specified, the gaps are of no us jframe.setLayout(new BorderLayout(7, 7));
  • 21. // each button covers the whole area // however, the btn5 is the latest button // that is added to the frame; therefore, btn5 // is shown jframe.add(btn1); jframe.add(btn2); jframe.add(btn3); jframe.add(btn4); jframe.add(btn5); jframe.setSize(300,300); jframe.setVisible(true); }
  • 22. // main method public static void main(String argvs[]) { new BorderLayoutWithoutRegion Example(); } }