Null
Home Up Border Card Flow Grid Null

 

Null Layout

There is only one way to invoke the null layout manager:

  1. setLayout(null);

The null layout manager gives the programmer complete control over where the components are placed.  Consequently, it is a very good manager to use when you want a professional looking interface on a variety of platforms. 

Example

In the example below, two buttons are created and placed on the window.  Since the null layout manager is being used, the programmer must specify the location and size of each button.  The "setBounds" methods takes four integer arguments: the x and y coordinates of the upper left corner of the component, the width in pixels of the component, and the height in pixels of the component.  Remember that coordinate (0,0) is the upper left corner of the entire window.  Thus, in the example below, the first button (50 pixels wide by 50 pixels high) appears at (0, 0) and the second button (50 pixels wide by 50 pixels high) appears at (100, 0).

import java.awt.*;
import java.applet.*;        
public class Null extends Applet
{
	public void init ()
	{
		setLayout(null);        
		Button b = new Button("1");
		b.setBounds(0, 0, 50, 50);
		add(b);        
		b = new Button("2");
		b.setBounds(100, 0, 50, 50);
		add(b);        
	}
		        
}      
What You'll See: