BorderLayout

Border Layout

The Border Layout manager provides you to position components using the directions North, South, East, West and Center. Border Layout class has five constraint.

These are used in adding components in the container.

BorderLayout.NORTH
BorderLayout.SOUTH
BorderLayout.EAST
BorderLayout.WEST
BorderLayout.CENTER

Program

1

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;

class Frame extends JFrame {
   
    Frame()
    {
        setTitle("BorderLayout");
        setLayout(new BorderLayout());
        setButton();
        setSize(700,200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    private void setButton()
    {
        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 JButton("CENTER"),BorderLayout.CENTER);
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
       Frame fr = new Frame();
    }
}

Leave a Comment