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

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

Introduction

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

Prototype

public Composite(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

From source file:ControlListenerAdd.java

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

    shell.setLayout(new RowLayout());

    final Composite composite = new Composite(shell, SWT.BORDER);
    composite.setLayout(new RowLayout());
    composite.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
    composite.addControlListener(new ControlListener() {
        public void controlMoved(ControlEvent e) {
        }// w  ww. ja va2  s  . c  o m

        public void controlResized(ControlEvent e) {
            System.out.println("Composite resize.");
        }
    });

    Button buttonAdd = new Button(shell, SWT.PUSH);
    buttonAdd.setText("Add new button");
    buttonAdd.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button button = new Button(composite, SWT.PUSH);
            button.setText("Button #" + (count++));
            composite.layout(true);
            composite.pack();
        }
    });

    shell.setSize(450, 100);
    shell.open();

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

From source file:ScrollCompisiteHoriVertical.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SashForm Test");
    shell.setLayout(new FillLayout());

    //  Create the ScrolledComposite to scroll horizontally and vertically
    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);

    Composite child = new Composite(sc, SWT.NONE);
    child.setLayout(new FillLayout());

    new Button(child, SWT.PUSH).setText("One");
    new Button(child, SWT.PUSH).setText("Two");

    child.setSize(400, 400);/*from   w w  w  .  ja  v a2  s  . c o m*/

    sc.setContent(child);

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

}

From source file:ScrolledCompositeMiniSize.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SashForm Test");
    shell.setLayout(new FillLayout());

    // Create the ScrolledComposite to scroll horizontally and vertically
    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);

    Composite child = new Composite(sc, SWT.NONE);
    child.setLayout(new FillLayout());

    new Button(child, SWT.PUSH).setText("One");
    new Button(child, SWT.PUSH).setText("Two");

    sc.setMinSize(400, 400);/*  ww w .j a  v  a2 s.  c  o  m*/

    // Expand both horizontally and vertically
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    sc.setContent(child);

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

}

From source file:PopupMenuComposite.java

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

    shell.setLayout(new GridLayout(2, true));

    final Composite composite1 = new Composite(shell, SWT.BORDER);
    composite1.setBackground(display.getSystemColor(SWT.COLOR_BLACK));

    final Composite composite2 = new Composite(shell, SWT.BORDER);
    composite2.setBackground(display.getSystemColor(SWT.COLOR_BLUE));

    Menu menu = new Menu(composite1);
    MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
    menuItem.setText("Popup menu");

    menuItem.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            System.out.println("Menu item is disposed.");
        }/*  ww w.j  a  v  a 2 s .  co  m*/
    });

    menuItem.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println("Dispsoing ...");
            composite2.setMenu(null);
            composite2.dispose();
        }
    });

    composite1.setMenu(menu);
    composite2.setMenu(menu);

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

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            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;/*www .  ja v  a2  s  .  c  o m*/
    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: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;//from www.j  av a 2 s .c  o  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:CoolBarComposite.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    CoolBar coolBar = new CoolBar(shell, SWT.BORDER);
    coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final CoolItem item = new CoolItem(coolBar, SWT.DROP_DOWN);

    Composite c = new Composite(coolBar, SWT.NONE);
    c.setLayout(new GridLayout(1, false));
    new Button(c, SWT.PUSH).setText("Button One");
    new Button(c, SWT.PUSH).setText("Button Two");

    item.setControl(c);//from w w  w  .  j a  v a 2s.  c o  m

    Control control = item.getControl();
    Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    pt = item.computeSize(pt.x, pt.y);
    item.setSize(pt);

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

From source file:ControlEditorWithDialog.java

public static void main(String[] args) {

    final Shell shell = new Shell(display);
    shell.setText("Control Editor Two");

    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setBackground(color);//www.  ja  v  a2s .  c o m
    composite.setBounds(0, 0, 300, 100);

    ControlEditor editor = new ControlEditor(composite);

    // Create the control associated with the editor
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Change Color...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dialog = new ColorDialog(shell);
            if (color != null)
                dialog.setRGB(color.getRGB());
            RGB rgb = dialog.open();
            if (rgb != null) {
                if (color != null)
                    color.dispose();
                color = new Color(shell.getDisplay(), rgb);
                composite.setBackground(color);
            }
        }
    });
    // Place the editor along the bottom of the parent composite
    editor.grabHorizontal = true;
    editor.verticalAlignment = SWT.BOTTOM;
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    editor.minimumHeight = size.y;
    editor.setEditor(button);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    if (color != null)
        color.dispose();
    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  ww.j  a  va  2s. c  o m*/

    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:Snippet115.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout(SWT.VERTICAL));
    Composite c1 = new Composite(shell, SWT.BORDER | SWT.NO_RADIO_GROUP);
    c1.setLayout(new RowLayout());
    Composite c2 = new Composite(shell, SWT.BORDER | SWT.NO_RADIO_GROUP);
    c2.setLayout(new RowLayout());
    final Composite[] composites = new Composite[] { c1, c2 };
    Listener radioGroup = new Listener() {
        public void handleEvent(Event event) {
            for (int i = 0; i < composites.length; i++) {
                Composite composite = composites[i];
                Control[] children = composite.getChildren();
                for (int j = 0; j < children.length; j++) {
                    Control child = children[j];
                    if (child instanceof Button) {
                        Button button = (Button) child;
                        if ((button.getStyle() & SWT.RADIO) != 0)
                            button.setSelection(false);
                    }/*  w w w . j  av a  2s. c  o m*/
                }
            }
            Button button = (Button) event.widget;
            button.setSelection(true);
        }
    };
    for (int i = 0; i < 4; i++) {
        Button button = new Button(c1, SWT.RADIO);
        button.setText("Button " + i);
        button.addListener(SWT.Selection, radioGroup);
    }
    for (int i = 0; i < 4; i++) {
        Button button = new Button(c2, SWT.RADIO);
        button.setText("Button " + (i + 4));
        button.addListener(SWT.Selection, radioGroup);
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}