No Layout Manager

While the GridBagLayout manager provides you with considerable flexibility, it is also rather Byzantine in its complexity. It's main advantage is flexibility where resizing is needed. If, however, you do not require resizing, you may find it preferable to provide explicit coordinates, width, and height for each component in the interface. If this is practical, you may use the No Layout manger option.

To provide your own explicit layout, you must do two things. First, setLayout ( null ) for the component or container. Then, use a reshape statement for each included component, providing four parameters: the x and y coordinates for the upper left corner of the component, followed by the width and height for the component. See the example code, below.

Below is code for a No Layout applet. The applet duplicates much of the code discussed with earlier Layout Managers; however, since the GridBagLayout discussion branched off into new territory, the complete program is shown.

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

public class step6 extends Applet{

// Illustrates No Layout

Frame outerBox = new Frame ( );

Button button1 = new Button ( "Button 1" );
Button button2 = new Button ( "Button 2" );
Button button3 = new Button ( "Button 3" );
Button button4 = new Button ( "Button 4" );
Button button5 = new Button ( "Button 5" );
Button button6 = new Button ( "Button 6" );

  public void init ( ){

    button1.setBackground ( Color.red );
    button2.setBackground ( Color.lightGray );
    button3.setBackground ( Color.cyan );
    button4.setBackground ( Color.yellow );
    button5.setBackground ( Color.green );
    button6.setBackground ( Color.orange );

    outerBox.setLayout ( null );
    outerBox.setBackground ( Color.white );
    outerBox. setFont (new Font ("Helvetica", Font.PLAIN, 18) );
    outerBox.resize (600, 500);

    outerBox.add ( button1 );
    outerBox.add ( button2 );
    outerBox.add ( button3 );
    outerBox.add ( button4 );
    outerBox.add ( button5 );
    outerBox.add ( button6 );

    button1.reshape ( 40, 80, 90, 40 );
    button2.reshape ( 150, 200, 200, 80 );
    button3.reshape ( 450, 150, 100, 200 );
    button4.reshape ( 80, 400, 90, 40 );
    button5.reshape ( 190, 400, 200, 40 );
    button6.reshape ( 410, 400, 120, 40 );

    outerBox.show( );

  } // end init

}// end step6 

Run the applet