Developer community
0 votes
4k views
asked by Sr Member (4.8k points) 10 23 31 | 4k views

1 Answer

0 votes

This Layout will display the components along the border of the container. This Layout contains five locations where the component can be displayed. Locations are North, South, East, West and Center(N,S,E,W & C).

*Creation of BorderLayout:

               BorderLayout bl = new BorderLayout(();

               BorderLayout bl = new BorderLayout(int vgap, int hgap);

import javax.swing.*;

import java.awt.*;

class LayoutDemo extends JFrame{

JButton b1, b2, b3, b4, b5;

Layoutdemo(){

b1 = new JButton(“Button1”);

b2 = new JButton(“Button2”);

b3 = new JButton(“Button3”);

b4 = new JButton(“Button4”);

b5 = new JButton(“Button5”);

Container c = this.ContentPane();

BorderLayout bl = new BorderLayout(10,20);

c.setLayout(bl);

c.add(“North”b1);

c.add(“South”b2);

c.add(“East”b3);

c.add(“West”b4);

c.add(“Center”b5);

setVisible(true);

setSize(400,400);

setTitle(“BorderDemo”);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

           }

public static void main(String[] args){

new LayoutDemo();

            }

}

To add the components in Border Layout we use add method.

            add(“North”,Component);

            add(Component, BorderLayout, NORTH);

answered by Expert (15k points) 15 23 29

Related questions

0 votes
1 answer
asked by sunny Expert (11.4k points) 14 22 28 | 4.2k views
+1 vote
1 answer
asked by augustaina Sr Member (4.8k points) 10 23 31 | 4.3k views
+1 vote
1 answer
asked by augustaina Sr Member (4.8k points) 10 23 31 | 4.4k views
0 votes
1 answer
asked by rock Expert (15k points) 15 23 29 | 31 views
0 votes
1 answer
asked by sara Guru (24.6k points) 29 51 77 | 120 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users