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

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

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Composite setLayout.

Prototype

public void setLayout(Layout layout) 

Source Link

Document

Sets the layout which is associated with the receiver to be the argument which may be null.

Usage

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. j a  v a  2  s  . co m*/

    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:org.eclipse.swt.snippets.Snippet266.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 266");
    shell.setLayout(new GridLayout(2, true));

    TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
    tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    TabItem item = new TabItem(tabFolder, SWT.NONE);
    item.setText("Widget");
    Composite composite = new Composite(tabFolder, SWT.NONE);
    composite.setLayout(new GridLayout());
    Tree tree = new Tree(composite, SWT.BORDER);
    item.setControl(composite);/*  www . ja v  a  2  s  .com*/
    tree.setHeaderVisible(true);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    TreeColumn column1 = new TreeColumn(tree, SWT.NONE);
    column1.setText("Standard");
    TreeColumn column2 = new TreeColumn(tree, SWT.NONE);
    column2.setText("Widget");
    TreeItem branch = new TreeItem(tree, SWT.NONE);
    branch.setText(new String[] { "Efficient", "Portable" });
    TreeItem leaf = new TreeItem(branch, SWT.NONE);
    leaf.setText(new String[] { "Cross", "Platform" });
    branch.setExpanded(true);
    branch = new TreeItem(tree, SWT.NONE);
    branch.setText(new String[] { "Native", "Controls" });
    leaf = new TreeItem(branch, SWT.NONE);
    leaf.setText(new String[] { "Cross", "Platform" });
    branch = new TreeItem(tree, SWT.NONE);
    branch.setText(new String[] { "Cross", "Platform" });
    column1.pack();
    column2.pack();

    item = new TabItem(tabFolder, SWT.NONE);
    item.setText("Toolkit");

    Button button = new Button(shell, SWT.CHECK);
    button.setText("Totally");
    button.setSelection(true);
    button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));

    button = new Button(shell, SWT.PUSH);
    button.setText("Awesome");
    button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));

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

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 343");
    shell.setLayout(new FillLayout());
    shell.setSize(400, 400);/*from  ww w .j  a  va  2  s  .  com*/
    SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);
    Composite leftComposite = new Composite(sashForm, SWT.NONE);
    leftComposite.setLayout(new FillLayout());
    Composite rightComposite = new Composite(sashForm, SWT.NONE);
    rightComposite.setLayout(new FillLayout());
    ExpandBar expandBar = new ExpandBar(leftComposite, SWT.NONE);
    final ExpandItem expandItem1 = new ExpandItem(expandBar, SWT.NONE);
    expandItem1.setText("item 1");
    new ExpandItem(expandBar, SWT.NONE).setText("item 2"); /* expandItem2 */

    final StyledText text = new StyledText(expandBar, SWT.MULTI | SWT.WRAP);
    expandItem1.setControl(text);
    text.setText("initial text that will wrap if it's long enough");

    /* update the item's height if needed in response to changes in the text's size */
    final int TRIAL_WIDTH = 100;
    final int trimWidth = text.computeTrim(0, 0, TRIAL_WIDTH, 100).width - TRIAL_WIDTH;
    text.addListener(SWT.Modify, event -> {
        Point size = text.computeSize(text.getSize().x - trimWidth, SWT.DEFAULT);
        if (expandItem1.getHeight() != size.y) {
            expandItem1.setHeight(size.y);
        }
    });
    expandBar.addListener(SWT.Resize, event -> display.asyncExec(() -> {
        /*
         * The following is done asynchronously to allow the Text's width
         * to be changed before re-calculating its preferred height.
         */
        if (text.isDisposed())
            return;
        Point size = text.computeSize(text.getSize().x - trimWidth, SWT.DEFAULT);
        if (expandItem1.getHeight() != size.y) {
            expandItem1.setHeight(size.y);
        }
    }));

    shell.open();
    /* set the item's initial height */
    Point size = text.computeSize(expandBar.getClientArea().width, SWT.DEFAULT);
    expandItem1.setHeight(size.y);
    expandItem1.setExpanded(true);

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

From source file:SWTGridLayout.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setSize(300, 200);//www  . jav a  2 s.  c o  m
    shell.setLayout(new RowLayout());

    final Composite composite = new Composite(shell, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 4;
    composite.setLayout(gridLayout);

    for (int loopIndex = 0; loopIndex < 18; loopIndex++) {
        Button button = new Button(composite, SWT.PUSH);
        button.setText("Button " + loopIndex);
    }

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

From source file:Snippet46.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setEnabled(false);// w w  w .  jav  a  2s. com
    composite.setLayout(new FillLayout());
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Button");
    composite.pack();
    composite.setLocation(10, 10);
    final Point[] offset = new Point[1];
    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.MouseDown:
                Rectangle rect = composite.getBounds();
                if (rect.contains(event.x, event.y)) {
                    Point pt1 = composite.toDisplay(0, 0);
                    Point pt2 = shell.toDisplay(event.x, event.y);
                    offset[0] = new Point(pt2.x - pt1.x, pt2.y - pt1.y);
                }
                break;
            case SWT.MouseMove:
                if (offset[0] != null) {
                    Point pt = offset[0];
                    composite.setLocation(event.x - pt.x, event.y - pt.y);
                }
                break;
            case SWT.MouseUp:
                offset[0] = null;
                break;
            }
        }
    };
    shell.addListener(SWT.MouseDown, listener);
    shell.addListener(SWT.MouseUp, listener);
    shell.addListener(SWT.MouseMove, listener);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 46");
    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setEnabled(false);//from  w  ww. j a  v  a2  s.  c  om
    composite.setLayout(new FillLayout());
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Button");
    composite.pack();
    composite.setLocation(10, 10);
    final Point[] offset = new Point[1];
    Listener listener = event -> {
        switch (event.type) {
        case SWT.MouseDown:
            Rectangle rect = composite.getBounds();
            if (rect.contains(event.x, event.y)) {
                Point pt1 = composite.toDisplay(0, 0);
                Point pt2 = shell.toDisplay(event.x, event.y);
                offset[0] = new Point(pt2.x - pt1.x, pt2.y - pt1.y);
            }
            break;
        case SWT.MouseMove:
            if (offset[0] != null) {
                Point pt = offset[0];
                composite.setLocation(event.x - pt.x, event.y - pt.y);
            }
            break;
        case SWT.MouseUp:
            offset[0] = null;
            break;
        }
    };
    shell.addListener(SWT.MouseDown, listener);
    shell.addListener(SWT.MouseUp, listener);
    shell.addListener(SWT.MouseMove, listener);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] arg) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Skin example");
    shell.setLayout(new GridLayout());

    Group container = new Group(shell, SWT.None);
    container.setText("Container");
    container.setLayout(new GridLayout(3, false));

    Composite child1 = new Composite(container, SWT.BORDER);
    child1.setLayout(new GridLayout());
    new Label(child1, SWT.NONE).setText("Label in pane 1");

    Composite child2 = new Composite(container, SWT.BORDER);
    child2.setLayout(new GridLayout());
    new Button(child2, SWT.PUSH).setText("Button in pane2");

    final Composite child3 = new Composite(container, SWT.BORDER);
    child3.setLayout(new GridLayout());
    new Text(child3, SWT.BORDER).setText("Text in pane3");

    display.addListener(SWT.Skin, event -> {
        System.out.println("Skin: " + event.widget);
        setBackground(event.display, (Control) event.widget);
    });/* w  w  w  .j  a  va 2 s  .  c  o  m*/

    Composite buttonContainer = new Composite(shell, SWT.NONE);
    buttonContainer.setLayout(new GridLayout(3, false));
    Button reskin = new Button(buttonContainer, SWT.PUSH);
    reskin.setText("Reskin All");
    reskin.addSelectionListener(widgetSelectedAdapter(e -> {
        System.out.println("=======");
        shell.reskin(SWT.ALL);
    }));
    Button reskin2 = new Button(buttonContainer, SWT.PUSH);
    reskin2.setText("Reskin Shell");
    reskin2.addSelectionListener(widgetSelectedAdapter(e -> {
        System.out.println("=======");
        shell.reskin(SWT.None);
    }));
    Button reskin3 = new Button(buttonContainer, SWT.PUSH);
    reskin3.setText("Reskin Right Composite");
    reskin3.addSelectionListener(widgetSelectedAdapter(e -> {
        System.out.println("=======");
        child3.reskin(SWT.ALL);
    }));

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

From source file:Snippet75.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());

    Composite c1 = new Composite(shell, SWT.BORDER);
    c1.setLayout(new RowLayout());
    Button b1 = new Button(c1, SWT.PUSH);
    b1.setText("B1");
    Button[] radios = new Button[3];
    for (int i = 0; i < radios.length; i++) {
        radios[i] = new Button(c1, SWT.RADIO);
        radios[i].setText("R" + (i == 1 ? "&" : "") + i);
    }/* w w  w. ja  v  a 2  s.  co m*/
    Button b2 = new Button(c1, SWT.PUSH);
    b2.setText("B2");
    List l1 = new List(c1, SWT.SINGLE | SWT.BORDER);
    l1.setItems(new String[] { "L1" });
    Button b3 = new Button(c1, SWT.PUSH);
    b3.setText("B&3");
    Button b3_1 = new Button(c1, SWT.PUSH);
    b3_1.setText("B3_1");

    Composite c2 = new Composite(shell, SWT.BORDER);
    c2.setLayout(new RowLayout());
    Button b4 = new Button(c2, SWT.PUSH);
    b4.setText("B&4");
    Button b5 = new Button(c2, SWT.PUSH);
    b5.setText("B&5");

    List l2 = new List(shell, SWT.SINGLE | SWT.BORDER);
    l2.setItems(new String[] { "L2" });

    ToolBar tb1 = new ToolBar(shell, SWT.FLAT | SWT.BORDER);
    ToolItem i1 = new ToolItem(tb1, SWT.RADIO);
    i1.setText("I1");
    ToolItem i2 = new ToolItem(tb1, SWT.RADIO);
    i2.setText("I&2");
    Combo combo1 = new Combo(tb1, SWT.READ_ONLY | SWT.BORDER);
    combo1.setItems(new String[] { "C1" });
    combo1.setText("C1");
    combo1.pack();
    ToolItem i3 = new ToolItem(tb1, SWT.SEPARATOR);
    i3.setWidth(combo1.getSize().x);
    i3.setControl(combo1);
    i3.setText("I3");
    ToolItem i4 = new ToolItem(tb1, SWT.PUSH);
    i4.setText("I4");
    ToolItem i5 = new ToolItem(tb1, SWT.CHECK);
    i5.setText("I5");

    Button b6 = new Button(shell, SWT.PUSH);
    b6.setText("B&6");

    Composite c4 = new Composite(shell, SWT.BORDER);
    c4.setSize(32, 32);
    Composite c5 = new Composite(c4, SWT.BORDER);
    c5.setSize(20, 20);

    Control[] list1 = new Control[] { b2, b1, b3_1, b3 };
    c1.setTabList(list1);
    Control[] list2 = new Control[] { c1, b6, tb1, c4, c2, l2 };
    shell.setTabList(list2);

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

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

From source file:Snippet6.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    final Composite c = new Composite(shell, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;//  w w w.j  a va 2s.co  m
    c.setLayout(layout);
    for (int i = 0; i < 10; i++) {
        Button b = new Button(c, SWT.PUSH);
        b.setText("Button " + i);
    }

    Button b = new Button(shell, SWT.PUSH);
    b.setText("add a new button at row 2 column 1");
    final int[] index = new int[1];
    b.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            Button s = new Button(c, SWT.PUSH);
            s.setText("Special " + index[0]);
            index[0]++;
            Control[] children = c.getChildren();
            s.moveAbove(children[3]);
            shell.layout(new Control[] { s });
        }
    });

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

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 6");
    shell.setLayout(new GridLayout());
    final Composite c = new Composite(shell, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;/*  w w w .  j  a  va2  s.c  om*/
    c.setLayout(layout);
    for (int i = 0; i < 10; i++) {
        Button b = new Button(c, SWT.PUSH);
        b.setText("Button " + i);
    }

    Button b = new Button(shell, SWT.PUSH);
    b.setText("add a new button at row 2 column 1");
    final int[] index = new int[1];
    b.addListener(SWT.Selection, e -> {
        Button s = new Button(c, SWT.PUSH);
        s.setText("Special " + index[0]);
        index[0]++;
        Control[] children = c.getChildren();
        s.moveAbove(children[3]);
        shell.layout(new Control[] { s });
    });

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