Showing posts with label awt Insets. Show all posts
Showing posts with label awt Insets. Show all posts

Apr 17, 2012

Insets


If you want to leave a small space between the container that holds your components and the window that contains it. To do this, override the getInsets() method that is defined by the container.
      
          Insets(int top, int left, int bottom, int right)

The values passed in top, left,  bottom and right specify the amount of space between the container and its enclosing window.

Example:

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


public class InsetsDemo extends Applet
{
 
        public void init()
        {
            setBackground(Color.cyan);
            setLayout(new BorderLayout());
            add(new Button("RMI"),BorderLayout.NORTH);
            add(new Button("SERVLET"),BorderLayout.EAST);
            add(new Button("JDBC"),BorderLayout.SOUTH);
            add(new Button("BEANS"),BorderLayout.WEST);
            add(new Button("JAVA"),BorderLayout.CENTER);
        }


        public Insets getInsets()
        {
            return new Insets(10,20,10,20);
        }
}
/*
<applet code=”InsetsDemo.class” width=300 height=200>
</applet>
*/

How to Execute this Example??

d:\>  javac InsetsDemo.java
d:\>  appletviewer InsetsDemo.java

Output: