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

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

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Composite 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:org.eclipse.swt.snippets.Snippet40.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 40");
    shell.setLayout(new GridLayout(2, false));
    Composite c1 = new Composite(shell, SWT.BORDER);
    c1.setLayoutData(new GridData(100, 100));
    Composite c2 = new Composite(shell, SWT.BORDER);
    c2.setLayoutData(new GridData(100, 100));
    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Popup");
    c1.setMenu(menu);//www .j  ava 2  s  .  c o m
    c2.setMenu(menu);
    shell.setMenu(menu);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ViewFormCreate.java

public static void main(String[] args) {

    Shell shell = new Shell(display);
    shell.setText("Look");

    shell.setLayout(new GridLayout(1, false));

    Button button = new Button(shell, SWT.PUSH);
    button.setText("New Document");

    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new FillLayout());

    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            createViewFormHelper(composite, "Document " + (++count));
            composite.layout();/*from  w  ww .  j  a va2s .com*/
        }
    });

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

From source file:MainClass.java

public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);

    GridLayout gl = new GridLayout();
    gl.numColumns = 4;/* ww  w.j  a  va2 s . c om*/
    s.setLayout(gl);
    s.setSize(250, 275);

    s.setText("A Shell Composite Example");

    s.setLayout(gl);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 4;
    gd = new GridData();

    Composite c1 = new Composite(s, SWT.NO_FOCUS);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    c1.setLayoutData(gd);
    Composite c2 = new Composite(s, SWT.NO_FOCUS);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    c2.setLayoutData(gd);

    Composite c = new Composite(s, SWT.NO_FOCUS);
    c.setLayout(new RowLayout());
    Button b1 = new Button(c, SWT.PUSH | SWT.BORDER);
    b1.setText("OK");
    Button b2 = new Button(c, SWT.PUSH | SWT.BORDER);
    b2.setText("Cancel");
    gd = new GridData(GridData.FILL_HORIZONTAL);
    c.setLayoutData(gd);

    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:GridLayoutComplex.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;// w  w w.j a  va 2 s. c  om
    layout.makeColumnsEqualWidth = true;
    shell.setLayout(layout);

    // Create the big button in the upper left
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 200;
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);

    // Create a composite to hold the three buttons in the upper right
    Composite composite = new Composite(shell, SWT.NONE);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    composite.setLayoutData(data);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginHeight = 15;
    composite.setLayout(layout);

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

From source file:MainClass.java

public static void main(String[] a) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);//from  w w w  .jav a 2s.com

    shell.setLayout(new GridLayout(1, false));

    Composite sash = new Composite(shell, SWT.NONE);
    sash.setLayout(new FillLayout());
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    final SashForm sashForm = new SashForm(sash, SWT.HORIZONTAL);

    sashForm.SASH_WIDTH = 5;

    sashForm.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    final Button one = new Button(sashForm, SWT.PUSH);
    one.setText("One");
    one.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            maximizeHelper(one, sashForm);
        }
    });

    final Button two = new Button(sashForm, SWT.PUSH);
    two.setText("Two");
    two.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            maximizeHelper(two, sashForm);
        }
    });

    final Button three = new Button(sashForm, SWT.PUSH);
    three.setText("Three");
    three.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            maximizeHelper(three, sashForm);
        }
    });

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

From source file:MainClass.java

public static void main(String[] a) {

    final Display d = new Display();
    final Shell shell = new Shell(d);

    shell.setSize(250, 200);// w  w w .ja v a  2  s  . com

    shell.setLayout(new GridLayout(1, false));

    Composite buttonBar = new Composite(shell, SWT.NONE);
    buttonBar.setLayout(new RowLayout());
    Button flip = new Button(buttonBar, SWT.PUSH);
    flip.setText("Switch Orientation");
    Button weights = new Button(buttonBar, SWT.PUSH);
    weights.setText("Restore Weights");

    Composite sash = new Composite(shell, SWT.NONE);
    sash.setLayout(new FillLayout());
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    final SashForm sashForm = new SashForm(sash, SWT.HORIZONTAL);

    sashForm.SASH_WIDTH = 5;

    sashForm.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    final Button one = new Button(sashForm, SWT.PUSH);
    one.setText("One");

    final Button two = new Button(sashForm, SWT.PUSH);
    two.setText("Two");

    final Button three = new Button(sashForm, SWT.PUSH);
    three.setText("Three");

    sashForm.setWeights(new int[] { 2, 2, 2 });

    flip.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            switch (sashForm.getOrientation()) {
            case SWT.HORIZONTAL:
                sashForm.setOrientation(SWT.VERTICAL);
                break;
            case SWT.VERTICAL:
                sashForm.setOrientation(SWT.HORIZONTAL);
                break;
            }
        }
    });

    weights.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            sashForm.setWeights(new int[] { 2, 2, 2 });
        }
    });

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

From source file:GridLayoutComplex.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;//from   ww  w. j  a  va2 s .co  m
    layout.makeColumnsEqualWidth = true;
    shell.setLayout(layout);

    // Create the big button in the upper left
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 200;
    Button one = new Button(shell, SWT.PUSH);
    one.setText("one");
    one.setLayoutData(data);

    // Create a composite to hold the three buttons in the upper right
    Composite composite = new Composite(shell, SWT.NONE);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    composite.setLayoutData(data);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginHeight = 15;
    composite.setLayout(layout);

    // Create button "two"
    data = new GridData(GridData.FILL_BOTH);
    Button two = new Button(composite, SWT.PUSH);
    two.setText("two");
    two.setLayoutData(data);

    // Create button "three"
    data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    Button three = new Button(composite, SWT.PUSH);
    three.setText("three");
    three.setLayoutData(data);

    // Create button "four"
    data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    Button four = new Button(composite, SWT.PUSH);
    four.setText("four");
    four.setLayoutData(data);

    // Create the long button across the bottom
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.horizontalSpan = 3;
    data.heightHint = 150;
    Button five = new Button(shell, SWT.PUSH);
    five.setText("five");
    five.setLayoutData(data);

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

From source file:MainClass.java

public static void main(String[] a) {

    final Display display = new Display();
    final Shell shell = new Shell(display);

    shell.setSize(250, 200);//from   w  w w  .j a  v a  2 s .  c o  m

    shell.setLayout(new FormLayout());

    Composite controls = new Composite(shell, SWT.NONE);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    controls.setLayoutData(data);

    final Browser browser = new Browser(shell, SWT.NONE);
    data = new FormData();
    data.top = new FormAttachment(controls);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    browser.setLayoutData(data);

    controls.setLayout(new GridLayout(6, false));

    Button button = new Button(controls, SWT.PUSH);
    button.setText("Back");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.back();
        }
    });

    button = new Button(controls, SWT.PUSH);
    button.setText("Forward");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.forward();
        }
    });

    button = new Button(controls, SWT.PUSH);
    button.setText("Refresh");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.refresh();
        }
    });

    button = new Button(controls, SWT.PUSH);
    button.setText("Stop");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.stop();
        }
    });

    final Text url = new Text(controls, SWT.BORDER);
    url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    url.setFocus();

    button = new Button(controls, SWT.PUSH);
    button.setText("Go");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.setUrl(url.getText());
        }
    });

    shell.setDefaultButton(button);

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

From source file:org.eclipse.swt.snippets.Snippet300.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("SWT and Swing DND Example");
    GridLayout layout = new GridLayout(1, false);
    shell.setLayout(layout);//  ww  w  .j a v  a  2  s.  c  o m

    Text swtText = new Text(shell, SWT.BORDER);
    swtText.setText("SWT Text");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    swtText.setLayoutData(data);
    setDragDrop(swtText);

    Composite comp = new Composite(shell, SWT.EMBEDDED);
    java.awt.Frame frame = SWT_AWT.new_Frame(comp);
    JTextField swingText = new JTextField(40);
    swingText.setText("Swing Text");
    swingText.setDragEnabled(true);
    frame.add(swingText);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = swingText.getPreferredSize().height;
    comp.setLayoutData(data);

    shell.setSize(400, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet313.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 313");
    shell.setLayout(new FormLayout());

    final Button button = new Button(shell, SWT.PUSH);
    button.setText(">>");
    FormData data = new FormData();
    data.top = new FormAttachment(0, 4);
    data.right = new FormAttachment(100, -4);
    button.setLayoutData(data);/*from  w w  w .  j  a va 2s .  co m*/

    final Composite composite = new Composite(shell, SWT.BORDER);
    final FormData down = new FormData();
    down.top = new FormAttachment(button, 4, SWT.BOTTOM);
    down.bottom = new FormAttachment(100, -4);
    down.left = new FormAttachment(0, 4);
    down.right = new FormAttachment(100, -4);
    final FormData up = new FormData();
    up.top = new FormAttachment(0);
    up.bottom = new FormAttachment(0);
    up.left = new FormAttachment(0);
    up.right = new FormAttachment(0);
    composite.setLayoutData(up);

    button.addSelectionListener(widgetSelectedAdapter(e -> {
        if (composite.getLayoutData() == up) {
            composite.setLayoutData(down);
            button.setText("<<");
        } else {
            composite.setLayoutData(up);
            button.setText(">>");
        }
        shell.pack();
    }));

    shell.pack();
    shell.open();

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