CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Swing > BorderLayout in Java Swing

Swing Tutorial

  • What Is Java Swing
  • First Program
  • What is AWT
  • Advantages of Swing Over AWT
  • JFrame
  • Swing Components
  • JLabel
  • JTextField
  • JPasswordField
  • JButton
  • Event Handling
  • FlowLayout
  • BorderLayout
  • GridLayout
  • GridBagLayout
  • BoxLayout
  • JPanel
  • JCheckBox
  • JRadioButton
  • Border Component
  • JComboBox
  • JList
  • JList with MVC
  • Mouse Event
  • Key Event
  • JMenuBar
  • JTextArea
  • Using Color
  • Use Font
  • Display Image/Icon
  • Dialog Box
  • JTable
  • JDesktopPane and JInternalFrame
  • JDesktopPane
  • JInternalFrame
  • Adapter Classes
  • Swing Timer
  • JScrollPane
  • JSlider
  • JProgressBar
  • JSeparator
  • JToolBar
  • ActionListener
  • ItemListener
  • Worker Thread
  • Nimbus Look and Feel

BorderLayout in Java Swing

BorderLayout in Java swing

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 · 1 min read · 0 Comments
Share: in X

BorderLayout is a layout manager in Java Swing that divides a container into five regions: North, South, East, West, and Center.

The North region is positioned at the top of the container, the South region at the bottom, the East region at the right, the West region at the left, and the Center region takes up the remaining space in the container.

To use BorderLayout in Java Swing, we can create a new instance of the BorderLayout class and set it as the layout manager for the container.

Example:

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class BorderLayoutDemo  extends JFrame {
    public BorderLayoutDemo() {
    	setTitle("BorderLayout Demo");
    	
        // Set the layout manager
        setLayout(new BorderLayout());

        // Add components to the container
        add(new JButton("North"), BorderLayout.NORTH);
        add(new JButton("South"), BorderLayout.SOUTH);
        add(new JButton("East"), BorderLayout.EAST);
        add(new JButton("West"), BorderLayout.WEST);
        add(new JLabel("Center"), BorderLayout.CENTER);

        // Set the size and make the frame visible
        setSize(300, 200);
        setVisible(true);
    }

    public static void main(String[] args) {
        new BorderLayoutDemo();
    }

}

Output:

BorderLayout Demo

Related Posts:

  • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
  • Control Statements in Java
  • Java Swing Tutorial
  • How to Install Ollama on Windows, Linux, and macOS:…
  • Identifiers in Java
  • MySQL Commands for Developers
Tags:javaswing
Was this article helpful?
← Previous ArticlePackages in Java: A Guide to Modular, Maintainable Code
Next Article →Interface in Java: Mastering Abstraction and Multiple Inheritance with Examples

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap