BorderLayout with vertical and horizontal gap

The BorderLayout class has the following constructors :

BorderLayout()

BorderLayout(int horizontal, int vertical)

The first one create the Default Border Layout. The second allows you to create a Border Layout with horizontal and vertical space left between components.

Program

1

 

 

 

Program Source

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

class Frame extends JFrame {
   
    Frame()
    {
        setTitle("BorderLayout with vertical and horizontel gap");
        setLayout(new BorderLayout(15,15));
        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