Example usage for org.eclipse.swt.widgets Button setLayoutData

List of usage examples for org.eclipse.swt.widgets Button setLayoutData

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Button setLayoutData.

Prototype

public void setLayoutData(Object layoutData) 

Source Link

Document

Sets the layout data associated with the receiver to the argument.

Usage

From source file:FormLayoutDialogDemo.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.WRAP);
    label.setText("Some text for your dialog.");
    List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    list.setItems(new String[] { "Item 1", "Item2" });
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("Ok");
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Cancel");

    final int insetX = 4, insetY = 4;
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = insetX;//  ww  w. j  a va 2  s.  co m
    formLayout.marginHeight = insetY;
    shell.setLayout(formLayout);

    Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    final FormData labelData = new FormData(size.x, SWT.DEFAULT);
    labelData.left = new FormAttachment(0, 0);
    labelData.right = new FormAttachment(100, 0);
    label.setLayoutData(labelData);
    shell.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event e) {
            Rectangle rect = shell.getClientArea();
            labelData.width = rect.width - insetX * 2;
            shell.layout();
        }
    });

    FormData button2Data = new FormData();
    button2Data.right = new FormAttachment(100, -insetX);
    button2Data.bottom = new FormAttachment(100, 0);
    button2.setLayoutData(button2Data);

    FormData button1Data = new FormData();
    button1Data.right = new FormAttachment(button2, -insetX);
    button1Data.bottom = new FormAttachment(100, 0);
    button1.setLayoutData(button1Data);

    FormData listData = new FormData();
    listData.left = new FormAttachment(0, 0);
    listData.right = new FormAttachment(100, 0);
    listData.top = new FormAttachment(label, insetY);
    listData.bottom = new FormAttachment(button2, -insetY);
    list.setLayoutData(listData);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();

}

From source file:Snippet65.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.WRAP);
    label.setText("This is a long text string that will wrap when the dialog is resized.");
    List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    list.setItems(new String[] { "Item 1", "Item2" });
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("Ok");
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Cancel");

    final int insetX = 4, insetY = 4;
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = insetX;//from  w ww.ja  v  a  2 s.  co m
    formLayout.marginHeight = insetY;
    shell.setLayout(formLayout);

    Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    final FormData labelData = new FormData(size.x, SWT.DEFAULT);
    labelData.left = new FormAttachment(0, 0);
    labelData.right = new FormAttachment(100, 0);
    label.setLayoutData(labelData);
    shell.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event e) {
            Rectangle rect = shell.getClientArea();
            labelData.width = rect.width - insetX * 2;
            shell.layout();
        }
    });

    FormData button2Data = new FormData();
    button2Data.right = new FormAttachment(100, -insetX);
    button2Data.bottom = new FormAttachment(100, 0);
    button2.setLayoutData(button2Data);

    FormData button1Data = new FormData();
    button1Data.right = new FormAttachment(button2, -insetX);
    button1Data.bottom = new FormAttachment(100, 0);
    button1.setLayoutData(button1Data);

    FormData listData = new FormData();
    listData.left = new FormAttachment(0, 0);
    listData.right = new FormAttachment(100, 0);
    listData.top = new FormAttachment(label, insetY);
    listData.bottom = new FormAttachment(button2, -insetY);
    list.setLayoutData(listData);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:DialogLayoutDemo.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.WRAP);
    label.setText("This is a long text string that will wrap when the dialog is resized.");
    List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    list.setItems(new String[] { "Item 1", "Item 2" });
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("OK");
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Cancel");

    final int insetX = 4, insetY = 4;
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = insetX;/*from  w  w w  .  ja v a  2  s . co m*/
    formLayout.marginHeight = insetY;
    shell.setLayout(formLayout);

    Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    final FormData labelData = new FormData(size.x, SWT.DEFAULT);
    labelData.left = new FormAttachment(0, 0);
    labelData.right = new FormAttachment(100, 0);
    label.setLayoutData(labelData);
    shell.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event e) {
            Rectangle rect = shell.getClientArea();
            labelData.width = rect.width - insetX * 2;
            shell.layout();
        }
    });

    FormData button2Data = new FormData();
    button2Data.right = new FormAttachment(100, -insetX);
    button2Data.bottom = new FormAttachment(100, 0);
    button2.setLayoutData(button2Data);

    FormData button1Data = new FormData();
    button1Data.right = new FormAttachment(button2, -insetX);
    button1Data.bottom = new FormAttachment(100, 0);
    button1.setLayoutData(button1Data);

    FormData listData = new FormData();
    listData.left = new FormAttachment(0, 0);
    listData.right = new FormAttachment(100, 0);
    listData.top = new FormAttachment(label, insetY);
    listData.bottom = new FormAttachment(button2, -insetY);
    list.setLayoutData(listData);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Ch6RowLayoutComposite.java

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

    RowLayout layout = new RowLayout(SWT.HORIZONTAL);
    setLayout(layout);/*from   w ww. j a  va2s.  com*/
    for (int i = 0; i < 16; ++i) {
        Button button = new Button(this, SWT.NONE);
        button.setText("Sample Text");
        button.setLayoutData(new RowData(200 + 5 * i, 20 + i));
    }
}

From source file:BugReport.java

public BugReport() {
    shell.setLayout(new GridLayout(1, true));
    shell.setImage(new Image(display, "java2s.gif"));
    shell.setText("Bug report page");

    Group groupBug = new Group(shell, SWT.NULL);
    groupBug.setText("Bug details");
    groupBug.setLayout(new GridLayout(2, false));
    groupBug.setLayoutData(new GridData(GridData.FILL_BOTH));

    new Label(groupBug, SWT.NULL).setText("Priority");
    Combo combo = new Combo(groupBug, SWT.BORDER);
    combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(groupBug, SWT.NULL).setText("Details");
    Text text = new Text(groupBug, SWT.BORDER | SWT.MULTI);
    text.setLayoutData(new GridData(GridData.FILL_BOTH));

    Group groupProxy = new Group(shell, SWT.NULL);
    groupProxy.setText("Connection setting");
    groupProxy.setLayout(new GridLayout(2, false));
    groupProxy.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(groupProxy, SWT.NULL).setText("Proxy host");
    Text textHost = new Text(groupProxy, SWT.SINGLE | SWT.BORDER);
    textHost.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    new Label(groupProxy, SWT.NULL).setText("Proxy port");
    Text textPort = new Text(groupProxy, SWT.SINGLE | SWT.BORDER);
    textPort.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button button = new Button(shell, SWT.PUSH);
    button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    //button.setAlignment(SWT.CENTER);
    button.setText("Submit bug report");

    shell.pack();/*w w  w  .ja v a2s  .  c om*/
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:RowLayoutSample.java

public RowLayoutSample() {
    RowLayout rowLayout = new RowLayout();
    //rowLayout.fill = true;
    //rowLayout.justify = true;
    //rowLayout.pack = false;
    //rowLayout.type = SWT.VERTICAL;
    //rowLayout.wrap = false;

    shell.setLayout(rowLayout);//from   w  w w .j  a  va  2  s  .  c  o  m

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");
    button1.setLayoutData(new RowData(100, 35));

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");

    //shell.setSize(120, 120);
    shell.pack();
    shell.open();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:GridLayoutSample.java

public GridLayoutSample() {

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;/*from w  w w . j av  a 2s .  c om*/
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");
    button1.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");
    list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");
    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_END);
    gridData.horizontalIndent = 5;
    button2.setLayoutData(gridData);

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("3");
    button3.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:Ch6GridLayoutAllOptionsComposite.java

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);/* www  . j  a v a2 s .co m*/
    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]));
        }
    }
}

From source file:GridLayoutSampleSpan.java

public GridLayoutSampleSpan() {

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;//from w w  w  . jav  a 2 s.  c o m
    gridLayout.makeColumnsEqualWidth = true;

    shell.setLayout(gridLayout);

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");
    button1.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));

    List list = new List(shell, SWT.BORDER);
    list.add("item 1");
    list.add("item 2");
    list.add("item 3");
    list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button #2");
    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_END);
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    button2.setLayoutData(gridData);

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("3");
    GridData gridData2 = new GridData(GridData.VERTICAL_ALIGN_END);
    gridData2.verticalSpan = 3;
    button3.setLayoutData(gridData2);

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:Ch6GridSpanComposite.java

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

    GridLayout layout = new GridLayout(3, false);
    setLayout(layout);//  w w w  . j  a v  a2 s . c om

    Button b = new Button(this, SWT.NONE);
    b.setText("Button 1");

    b = new Button(this, SWT.NONE);
    b.setText("Button 2");
    b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    b = new Button(this, SWT.NONE);
    b.setText("Button 3");

    Text t = new Text(this, SWT.MULTI);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    data.verticalSpan = 2;
    t.setLayoutData(data);

    b = new Button(this, SWT.NONE);
    b.setText("Button 4");
    b.setLayoutData(new GridData(GridData.FILL_VERTICAL));

    b = new Button(this, SWT.NONE);
    b.setText("Button 5");
    b.setLayoutData(new GridData(GridData.FILL_VERTICAL));

}