import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

public class GridLayoutDemo {

	public static Display myDisplay;
	public static boolean internalCall = false;

	public static void main(String[] args) {
		internalCall = true;
		myDisplay = new Display();
		GridLayoutDemo gld = new GridLayoutDemo();
		gld.runDemo(myDisplay);
	}
	
	public void runDemo(Display display) {
		myDisplay = display;
		Shell shell = new Shell(display);
		shell.setSize(300,200);
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		shell.setText("Grid Layout Demo");
		shell.setLayout(gridLayout);
		
		Label label1 = new Label(shell, SWT.NONE);
		label1.setText("Name:");
		Text text1 = new Text(shell, SWT.BORDER);
		Label label2 = new Label(shell, SWT.NONE);
		label2.setText("Age:");
		Text text2 = new Text(shell, SWT.BORDER);
		Label label3 = new Label(shell, SWT.NONE);
		label3.setText("Gender:");
		Text text3 = new Text(shell, SWT.BORDER);
		Button button = new Button(shell, SWT.CHECK);
		button.setText("Have you been employed in the past six months?");
		
		GridData data = new GridData();
		data.widthHint = 60;
		label1.setLayoutData(data);
		data = new GridData();
		data.widthHint = 60;
		label2.setLayoutData(data);
		data = new GridData();
		data.widthHint = 60;
		label3.setLayoutData(data);
		
		GridData data2 = new GridData(GridData.FILL_HORIZONTAL);
		text1.setLayoutData(data2);
		data2 = new GridData(GridData.FILL_HORIZONTAL);
		text2.setLayoutData(data2);
		data2 = new GridData(GridData.FILL_HORIZONTAL);
		text3.setLayoutData(data2);
		
		GridData data3 = new GridData();
		data3.horizontalSpan = 2;
		button.setLayoutData(data3);
		
		shell.open();
		
		while(!shell.isDisposed()){
		if(!display.readAndDispatch())
			display.sleep();
		}
		if (internalCall) display.dispose();
	}
}
