Ch6GridLayoutAllOptionsComposite.java Source code

Java tutorial

Introduction

Here is the source code for Ch6GridLayoutAllOptionsComposite.java

Source

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public class Ch6GridLayoutAllOptionsComposite extends Composite {

    public Ch6GridLayoutAllOptionsComposite(Composite parent) {
        super(parent, SWT.NONE);

        int[] fillStyles = { SWT.NONE, GridData.FILL_HORIZONTAL, GridData.FILL_VERTICAL, GridData.FILL_BOTH };

        int[] alignStyles = { SWT.NONE, GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.HORIZONTAL_ALIGN_END,
                GridData.HORIZONTAL_ALIGN_CENTER, GridData.HORIZONTAL_ALIGN_FILL, GridData.VERTICAL_ALIGN_BEGINNING,
                GridData.VERTICAL_ALIGN_END, GridData.VERTICAL_ALIGN_CENTER, GridData.VERTICAL_ALIGN_FILL };

        GridLayout layout = new GridLayout(fillStyles.length, false);
        setLayout(layout);
        int count = 0;
        for (int i = 0; i < alignStyles.length; ++i) {
            for (int j = 0; j < fillStyles.length; ++j) {
                Button button = new Button(this, SWT.NONE);
                button.setText("Cell " + count++);
                button.setLayoutData(new GridData(fillStyles[j] | alignStyles[i]));
            }
        }
    }
}