Submit Your Site To The Web's Top 50 Search Engines for Free!       ExactSeek: Relevant Web Search


Flag Counter

Total Pageviews

Sunday, November 18, 2012

BorderLayout on Java

A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER. When adding a component to a container with a border layout, use one of these five constants, for example:
import javax.swing.*;
import java.awt.*;

public class DemoBorderLayout extends JFrame{
    public DemoBorderLayout(){
        JPanel p1 = new JPanel();
        BorderLayout b = new BorderLayout();
        JButton btnNorth = new JButton("North");
        JButton btnWest = new JButton("West");
        JButton btnEast = new JButton("East");
        JButton btnSouth = new JButton("South");
        JButton btnCenter = new JButton("Center");
        p1.add(btnNorth, BorderLayout.NORTH);
        p1.add(btnWest, BorderLayout.WEST);
        p1.add(btnEast, BorderLayout.EAST);
        p1.add(btnSouth, BorderLayout.SOUTH);
        p1.add(btnCenter, BorderLayout.CENTER);

    public static void main (String[]aa) {
        JFrame frame = new DemoBorderLayout();

output : 

If the window is enlarged, the center area gets as much of the available space as possible. The other areas expand only as much as necessary to fill all available space. Often a container uses only one or two of the areas of the BorderLayout object — just the center, or the center and the bottom.BorderLayout on Java


Post a Comment