Advanced JAVA Laboratory Manual by Patel Gayatri

Advanced JAVA Laboratory Manual by Patel Gayatri

Author:Patel, Gayatri [Patel, Gayatri]
Language: eng
Format: azw3, pdf
Publisher: Osmora Inc.
Published: 2016-01-29T16:00:00+00:00


BorderLayout

The BorderLayout class implements a common layout style for top-level windows. It has four narrow, fixed-width components at the edges and one large area in the center. The four sides are referred to as north, south, east, and west. The middle area is called the center. Here are the constructors defined by BorderLayout:

BorderLayout( );

BorderLayout(int horz, int vert);

The first form creates a default border layout. The second allows us to specify the horizontal and vertical space left between components in horz and vert, respectively. BorderLayout defines the following constants that specify the regions:

BorderLayout.CENTER

BorderLayout.SOUTH

BorderLayout.EAST

BorderLayout.WEST

BorderLayout.NORTH

When adding components, we will use these constants with the following form of add( ), which is defined by Container:

void add(Component compObj, Object region);

Here, compObj is the component to be added, and region specifies where the component will be added. Here is an example of a BorderLayout with a component in each layout area:

// BorderLayoutDemo.java

import java.awt.*; import java.applet.*;

/*

<applet code=“BorderLayoutDemo” width=400 height=200>

</applet>

*/

public class BorderLayoutDemo extends Applet

{

public void init()

{

setLayout(new BorderLayout());

add(new Button(“This is across the top.”), BorderLayout.NORTH);

add(new Label(“The footer message might go here.”), BorderLayout.SOUTH);

add(new Button(“Right”), BorderLayout.EAST);

add(new Button(“Left”), BorderLayout.WEST);

String msg = “The reasonable man adapts ” +

“himself to the world;\n” +

“the unreasonable one persists in ” + “trying to adapt the world to himself.\n” + “Therefore all progress depends ” +

“on the unreasonable man.\n\n” +

” - George Bernard Shaw\n\n”;

add(new TextArea(msg),

BorderLayout.CENTER);

}

}

Output:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.