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

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    Button filterButton = new Button(composite, SWT.CHECK);
    filterButton.setText("&Show only healthy");

    final ListViewer lv = new ListViewer(composite);
    lv.setContentProvider(new ItemContentProvider());
    lv.setLabelProvider(new ItemLabelProvider());
    lv.setInput(new ItemList());

    filterButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            if (((Button) event.widget).getSelection())
                lv.addFilter(filter);//w  w  w.j ava 2 s. co  m
            else
                lv.removeFilter(filter);
        }
    });

    parent.pack();
    return composite;
}

From source file:Survey.java

/**
 * Creates the controls for this page//from  w  ww .  j  a  v a 2s  .  com
 */
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    new Label(composite, SWT.LEFT).setText("Please enter your complaints");
    Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    text.setLayoutData(new GridData(GridData.FILL_BOTH));

    setControl(composite);
}

From source file:CheckFileTreeViewer.java

/**
 * Creates the main window's contents/*from  www.  j  av  a2 s  . c om*/
 *
 * @param parent the main window
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    // Create the tree viewer to display the file tree
    final CheckboxTreeViewer tv = new CheckboxTreeViewer(composite);
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput("root"); // pass a non-null that will be ignored

    // When user checks a checkbox in the tree, check all its children
    tv.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
                tv.setSubtreeChecked(event.getElement(), true);
            }
        }
    });
    return composite;
}

From source file:Survey.java

/**
 * Creates the page controls//from   w  w  w.j av a 2 s .c om
 */
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    new Label(composite, SWT.LEFT).setText("Do you have complaints?");
    Composite yesNo = new Composite(composite, SWT.NONE);
    yesNo.setLayout(new FillLayout(SWT.VERTICAL));

    yes = new Button(yesNo, SWT.RADIO);
    yes.setText("Yes");

    no = new Button(yesNo, SWT.RADIO);
    no.setText("No");

    setControl(composite);
}

From source file:AsciiTable.java

/**
 * Creates the window's contents (the table)
 * //from w  w w  .ja v  a 2 s  .c  o  m
 * @param composite the parent composite
 */
private void createContents(Composite composite) {
    composite.setLayout(new FillLayout());

    // The system font will not display the lower 32
    // characters, so create one that will
    createFont();

    // Create a table with visible headers
    // and lines, and set the font that we
    // created
    Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setRedraw(false);
    table.setFont(font);

    // Create the columns
    TableColumn[] columns = createColumns(table);

    for (int i = 0; i < MAX_CHARS; i++) {
        // Create a background color for this row
        colors[i] = new Color(table.getDisplay(), 255 - i, 127 + i, i);

        // Create the row in the table by creating
        // a TableItem and setting text for each
        // column
        int c = 0;
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(c++, String.valueOf((char) i));
        item.setText(c++, String.valueOf(i));
        item.setText(c++, Integer.toHexString(i).toUpperCase());
        item.setText(c++, Integer.toOctalString(i));
        item.setText(c++, Integer.toBinaryString(i));
        item.setText(c++, i < CHAR_NAMES.length ? CHAR_NAMES[i] : "");
        item.setBackground(colors[i]);
    }

    // Now that we've set the text into the columns,
    // we call pack() on each one to size it to the
    // contents.
    for (int i = 0, n = columns.length; i < n; i++) {
        columns[i].pack();
    }

    // Set redraw back to true so that the table
    // will paint appropriately
    table.setRedraw(true);
}

From source file:TabComplex.java

/**
 * Gets the control for tab one//from ww  w  .java 2  s .c o m
 * 
 * @param tabFolder the parent tab folder
 * @return Control
 */
private Control getTabOneControl(TabFolder tabFolder) {
    // Create a composite and add four buttons to it
    Composite composite = new Composite(tabFolder, SWT.NONE);
    composite.setLayout(new FillLayout(SWT.VERTICAL));
    new Button(composite, SWT.PUSH).setText("Button one");
    new Button(composite, SWT.PUSH).setText("Button two");
    new Button(composite, SWT.PUSH).setText("Button three");
    new Button(composite, SWT.PUSH).setText("Button four");
    return composite;
}

From source file:TabComplex.java

/**
 * Gets the control for tab three//from   w w w .  j  av  a2s.  co m
 * 
 * @param tabFolder the parent tab folder
 * @return Control
 */
private Control getTabThreeControl(TabFolder tabFolder) {
    // Create some labels and text fields
    Composite composite = new Composite(tabFolder, SWT.NONE);
    composite.setLayout(new RowLayout());
    new Label(composite, SWT.LEFT).setText("Label One:");
    new Text(composite, SWT.BORDER);
    new Label(composite, SWT.RIGHT).setText("Label Two:");
    new Text(composite, SWT.BORDER);
    return composite;
}

From source file:FocusTraversal.java

private void init() {
    shell.setLayout(new RowLayout());

    Composite composite1 = new Composite(shell, SWT.BORDER);
    composite1.setLayout(new RowLayout());
    composite1.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

    Button button1 = new Button(composite1, SWT.PUSH);
    button1.setText("Button1");

    List list = new List(composite1, SWT.MULTI | SWT.BORDER);
    list.setItems(new String[] { "Item-1", "Item-2", "Item-3" });

    Button radioButton1 = new Button(composite1, SWT.RADIO);
    radioButton1.setText("radio-1");
    Button radioButton2 = new Button(composite1, SWT.RADIO);
    radioButton2.setText("radio-2");

    Composite composite2 = new Composite(shell, SWT.BORDER);
    composite2.setLayout(new RowLayout());
    composite2.setBackground(display.getSystemColor(SWT.COLOR_GREEN));

    Button button2 = new Button(composite2, SWT.PUSH);
    button2.setText("Button2");

    final Canvas canvas = new Canvas(composite2, SWT.NULL);
    canvas.setSize(50, 50);/*from   www  .  ja  v a2  s . c om*/
    canvas.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));

    Combo combo = new Combo(composite2, SWT.DROP_DOWN);
    combo.add("combo");
    combo.select(0);

    canvas.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            GC gc = new GC(canvas);
            // Erase background first. 
            Rectangle rect = canvas.getClientArea();
            gc.fillRectangle(rect.x, rect.y, rect.width, rect.height);

            Font font = new Font(display, "Arial", 32, SWT.BOLD);
            gc.setFont(font);

            gc.drawString("" + e.character, 15, 10);

            gc.dispose();
            font.dispose();
        }

        public void keyReleased(KeyEvent e) {
        }
    });

    canvas.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS)
                e.doit = true;
        }
    });

    composite1.setTabList(new Control[] { button1, list });
    composite2.setTabList(new Control[] { button2, canvas, combo });

    shell.setTabList(new Control[] { composite2, composite1 });
}

From source file:TabbedShellExample.java

TabbedShellExample() {
    d = new Display();
    s = new Shell(d);

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

    s.setText("A Tabbed Shell Example");
    s.setLayout(new FillLayout());

    TabFolder tf = new TabFolder(s, SWT.BORDER);

    TabItem ti1 = new TabItem(tf, SWT.BORDER);
    ti1.setText("Option Group");
    ti1.setControl(new GroupExample(tf, SWT.SHADOW_ETCHED_IN));

    TabItem ti2 = new TabItem(tf, SWT.BORDER);
    ti2.setText("Grid");
    ti2.setControl(new GridComposite(tf));

    TabItem ti3 = new TabItem(tf, SWT.BORDER);
    ti3.setText("Text");
    Composite c1 = new Composite(tf, SWT.BORDER);
    c1.setLayout(new FillLayout());
    Text t = new Text(c1, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    ti3.setControl(c1);

    TabItem ti4 = new TabItem(tf, SWT.BORDER);
    ti4.setText("Settings");
    Composite c2 = new Composite(tf, SWT.BORDER);
    c2.setLayout(new RowLayout());
    Text t2 = new Text(c2, SWT.BORDER | SWT.SINGLE | SWT.WRAP | SWT.V_SCROLL);
    Button b = new Button(c2, SWT.PUSH | SWT.BORDER);
    b.setText("Save");
    ti4.setControl(c2);

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

From source file:CoolBarTest.java

/**
 * Creates two stacked buttons/*  ww  w.j  a  v a2  s  .c  o  m*/
 * 
 * @param composite the parent composite
 * @return Control
 */
private Control createStackedButtons(Composite composite) {
    Composite c = new Composite(composite, SWT.NONE);
    c.setLayout(new GridLayout(1, false));
    new Button(c, SWT.PUSH).setText("Button One");
    new Button(c, SWT.PUSH).setText("Button Two");
    return c;
}