Saturday, 23 May 2015

Filled Under:

Tutorial On Border Layout In Java

Before using border layout or any other layout programmer should know when to use which layout because its depend on situation in each situation programmer can not use border layout.

BOREDER LAYOUT IN JAVA:

Border layout is used when we want to fill components in all available place.When the window is enlarge component occupy the all available area we can also use this layout to occupy any one or two of following area.
PAGE_START
PAGE_END
LINE_START
LINE_END
CENTER
Following program illustrates how to use each of these BorderLayout constant.

CODING:

import javax.swing.*;
import java.awt.*;
class myjframe1 extends JFrame
{

public myjframe1() 
{

setTitle("Border Layout");
setDefaultCloseOperation(EXIT_ON_CLOSE);      
setSize(400, 600);
setLayout(new BorderLayout(20,20));
JButton button = new JButton("Button with page start layout");
add(button,BorderLayout.PAGE_START);
JButton button1 = new JButton("Button with page end layout");
add(button1,BorderLayout.PAGE_END);
JButton button2 = new JButton("Button with line start layout");
add(button2,BorderLayout.LINE_START);
JButton button3 = new JButton("Button with line end layout");
add(button3,BorderLayout.LINE_END);
JButton button4 = new JButton("Button with center layout");
add(button4,BorderLayout.CENTER);
setVisible(true);
}
}
class simpframe
{
public static void main(String args[])
{
myjframe1 x= new myjframe1();
}
}

OUTPUT:



1 comments: