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

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new FillLayout());

    Canvas canvas = new Canvas(composite, SWT.NULL);

    LightweightSystem lws = new LightweightSystem(canvas);
    Button button = new Button("Button", new Image(getShell().getDisplay(), "java2s.gif"));
    lws.setContents(button);//from   www  .ja  va  2 s.  c o  m

    return composite;
}

From source file:ShowMyTitleAreaDialog.java

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

    // Create the button
    Button show = new Button(composite, SWT.NONE);
    show.setText("Show");

    final Shell shell = parent.getShell();

    // Display the TitleAreaDialog
    show.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create and show the dialog
            MyTitleAreaDialog dlg = new MyTitleAreaDialog(shell);
            dlg.open();
        }
    });

    parent.pack();
    return composite;
}

From source file:MainClass.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));

    final Button indeterminate = new Button(composite, SWT.CHECK);
    indeterminate.setText("Indeterminate");
    Button showProgress = new Button(composite, SWT.NONE);
    showProgress.setText("Show Progress");

    final Shell shell = parent.getShell();

    showProgress.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            try {
                new ProgressMonitorDialog(shell).run(true, true,
                        new LongRunningOperation(indeterminate.getSelection()));
            } catch (InvocationTargetException e) {
                MessageDialog.openError(shell, "Error", e.getMessage());
            } catch (InterruptedException e) {
                MessageDialog.openInformation(shell, "Cancelled", e.getMessage());
            }/*from w  w w . j ava  2 s .  c o m*/
        }
    });

    parent.pack();
    return composite;
}

From source file:RoundRectangleExample.java

/**
 * Creates the main window's contents//from   w w w  .j a v a  2  s.c o  m
 * 
 * @param shell the main window
 */
private void createContents(Shell shell) {
    shell.setLayout(new FillLayout(SWT.VERTICAL));

    // Create the composite that holds the input fields
    Composite widgetComposite = new Composite(shell, SWT.NONE);
    widgetComposite.setLayout(new GridLayout(2, false));

    // Create the input fields
    new Label(widgetComposite, SWT.NONE).setText("Arc Width:");
    txtArcWidth = new Text(widgetComposite, SWT.BORDER);

    new Label(widgetComposite, SWT.NONE).setText("Arc Height");
    txtArcHeight = new Text(widgetComposite, SWT.BORDER);

    // Create the button that launches the redraw
    Button button = new Button(widgetComposite, SWT.PUSH);
    button.setText("Redraw");
    shell.setDefaultButton(button);

    // Create the canvas to draw the round rectangle on
    final Canvas drawingCanvas = new Canvas(shell, SWT.NONE);
    drawingCanvas.addPaintListener(new RoundRectangleExamplePaintListener());

    // Add a handler to redraw the round rectangle when pressed
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            drawingCanvas.redraw();
        }
    });
}

From source file:TreeViewerFileFromTree.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new FillLayout());

    Tree tree = new Tree(composite, SWT.SINGLE);

    for (int i = 0; i < 4; i++) {
        TreeItem iItem = new TreeItem(tree, 0);
        iItem.setText("TreeItem (0) -" + i);
        for (int j = 0; j < 4; j++) {
            TreeItem jItem = new TreeItem(iItem, 0);
            jItem.setText("TreeItem (1) -" + j);
            for (int k = 0; k < 4; k++) {
                TreeItem kItem = new TreeItem(jItem, 0);
                kItem.setText("TreeItem (2) -" + k);
                for (int l = 0; l < 4; l++) {
                    TreeItem lItem = new TreeItem(kItem, 0);
                    lItem.setText("TreeItem (3) -" + l);
                    for (int m = 0; m < 4; m++) {
                        TreeItem mItem = new TreeItem(lItem, 0);
                        mItem.setText("TreeItem (3) -" + l);
                    }/*from  ww w  .  j a v a  2s  .  com*/

                }
            }
        }
    }

    TreeViewer treeViewer = new TreeViewer(tree);

    return composite;
}

From source file:SWTTreeExample.java

private void createContents(Composite composite) {
    // Set the single-selection tree in the upper left,
    // the multi-selection tree in the upper right,
    // and the checkbox tree across the bottom.
    // To do this, create a 1x2 grid, and in the top
    // cell, a 2x1 grid.
    composite.setLayout(new GridLayout(1, true));
    Composite top = new Composite(composite, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    top.setLayoutData(data);/* w  w  w  .j  a v  a 2s  .  c o m*/

    top.setLayout(new GridLayout(2, true));
    Tree single = new Tree(top, SWT.SINGLE | SWT.BORDER);
    data = new GridData(GridData.FILL_BOTH);
    single.setLayoutData(data);
    fillTree(single);

    Tree multi = new Tree(top, SWT.MULTI | SWT.BORDER);
    data = new GridData(GridData.FILL_BOTH);
    multi.setLayoutData(data);
    fillTree(multi);

    Tree check = new Tree(composite, SWT.CHECK | SWT.BORDER);
    data = new GridData(GridData.FILL_BOTH);
    check.setLayoutData(data);
    fillTree(check);
}

From source file:SimpleBrowser.java

/**
 * Creates the main window's contents/*from   www  .j  a  v  a 2 s .  c  o  m*/
 * 
 * @param shell the main window
 */
private void createContents(Shell shell) {
    shell.setLayout(new FormLayout());

    // Create the composite to hold the buttons and text field
    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);

    // Create the web browser
    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);

    // Create the controls and wire them to the browser
    controls.setLayout(new GridLayout(6, false));

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

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

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

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

    // Create the address entry field and set focus to it
    final Text url = new Text(controls, SWT.BORDER);
    url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    url.setFocus();

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

    // Allow users to hit enter to go to the typed URL
    shell.setDefaultButton(button);
}

From source file:SimpleForm.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new GridLayout());

    // Sets up the toolkit.
    FormToolkit toolkit = new FormToolkit(getShell().getDisplay());

    // create a form instance.
    Form form = toolkit.createForm(composite);
    form.setLayoutData(new GridData(GridData.FILL_BOTH));

    form.setText("Eclipse Forms");

    form.getBody().setLayout(new GridLayout());
    Button button = toolkit.createButton(form.getBody(), "Test", SWT.NULL);

    // tool bar//from   w  ww.  j a  v  a2 s .c o m
    form.getToolBarManager().add(new Action("TEST") {
        public void run() {
        }
    });

    Menu menu = new Menu(form.getBody());
    MenuItem item = new MenuItem(menu, SWT.NULL);
    item.setText("Testing item");
    form.setMenu(menu);

    form.updateToolBar();

    return composite;
}

From source file:GetInput.java

/**
 * Creates the main window's contents//from w  w  w  . ja va 2 s  .  c o m
 * 
 * @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 a label to display what the user typed in
    final Label label = new Label(composite, SWT.NONE);
    label.setText("This will display the user input from InputDialog");

    // Create the button to launch the error dialog
    Button show = new Button(composite, SWT.PUSH);
    show.setText("Get Input");
    show.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "", "Enter 5-8 characters",
                    label.getText(), new LengthValidator());
            if (dlg.open() == Window.OK) {
                // User clicked OK; update the label with the input
                label.setText(dlg.getValue());
            }
        }
    });

    parent.pack();
    return composite;
}

From source file:ControlEditorTestTwo.java

/**
 * Creates the main window's contents//  w ww  . ja  v  a 2  s . com
 * 
 * @param shell the main window
 */
private void createContents(final Shell shell) {
    color = new Color(shell.getDisplay(), 255, 0, 0);

    // Create a composite that will be the parent of the editor
    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setBackground(color);
    composite.setBounds(0, 0, 300, 100);

    // Create the editor
    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);
}