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:org.eclipse.swt.examples.browser.demos.views.BrowserDemoView.java

@Override
public void createPartControl(Composite parent) {
    this.parent = parent;
    parent.setLayout(new FillLayout());
    try {//from  w w w.ja va2 s .  com
        Browser browser = new Browser(parent, SWT.NONE);
        browser.dispose();
    } catch (SWTError e) {
        Text text = new Text(parent, SWT.MULTI | SWT.READ_ONLY);
        text.setText("Browser widget cannot be instantiated. The exact error is:\r\n" + e);
        text.requestLayout();
        return;
    }
    TabFolder folder = new TabFolder(parent, SWT.NONE);
    TabItem item = new TabItem(folder, SWT.NONE);
    new PawnTab(item);

    item = new TabItem(folder, SWT.NONE);
    new EditorTab(item);
}

From source file:Look.java

/**
 * Creates the main window's contents/*from w ww.  jav  a 2 s.  c o  m*/
 * 
 * @param parent the main window
 */
public void createContents(Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    // Pressing the "New Document" button will create a new ViewForm
    Button button = new Button(parent, SWT.PUSH);
    button.setText("New Document");

    // Create the composite that holds the ViewForms
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new FillLayout());

    // Add the event handler to create the ViewForms
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            createViewFormHelper(composite, "Document " + (++count));
            composite.layout();
        }
    });
}

From source file:RegistryTest.java

/**
 * Creates the window's contents/*w  ww  . ja  va  2 s  . c  om*/
 * 
 * @param parent the parent composite
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new FillLayout(SWT.VERTICAL));

    // Set up the registries
    CR = new ColorRegistry();
    CR.addListener(this);

    FR = new FontRegistry();
    FR.addListener(this);

    // Create the label
    label = new Label(composite, SWT.CENTER);
    label.setText("Hello from JFace");

    // Create the randomize button
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Randomize");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            CR.put(FOREGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255),
                    (int) (Math.random() * 255)));
            CR.put(BACKGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255),
                    (int) (Math.random() * 255)));
            FontData fontData = new FontData("Times New Roman", (int) (Math.random() * 72), SWT.BOLD);
            FR.put(FONT, new FontData[] { fontData });
        }
    });
    return composite;
}

From source file:GetInput.java

/**
 * Creates the main window's contents//from   w  w w  .  j av  a 2 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 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:RoundRectangleExample.java

/**
 * Creates the main window's contents//from www  . j a  va2  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:FileTreeWindowApplication.java

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

    final TreeViewer tv = new TreeViewer(composite);
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput("root");

    return composite;
}

From source file:TemperatureConverterJFace.java

protected Control createContents(Composite parent) {
    getShell().setText("JFace Temperature Converter");

    Composite converterComposite = new Composite(parent, SWT.NULL);

    converterComposite.setLayout(new GridLayout(4, false));

    fahrenheitLabel = new Label(converterComposite, SWT.NULL);
    fahrenheitLabel.setText("Fahrenheit: ");

    fahrenheitValue = new Text(converterComposite, SWT.SINGLE | SWT.BORDER);

    celsiusLabel = new Label(converterComposite, SWT.NULL);
    celsiusLabel.setText("Celsius: ");

    celsiusValue = new Text(converterComposite, SWT.SINGLE | SWT.BORDER);

    ModifyListener listener = new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            valueChanged((Text) e.widget);
        }//from  w w  w.  ja  v  a2  s  .  co m
    };

    fahrenheitValue.addModifyListener(listener);
    celsiusValue.addModifyListener(listener);

    return converterComposite;
}

From source file:EmailForm.java

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

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

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

    // Sets title.
    form.setText("Composing an Email Message");

    // Adds body contents.
    form.getBody().setLayout(new GridLayout(2, false));
    Label label = toolkit.createLabel(form.getBody(), "To: ", SWT.NULL);
    Text textTo = toolkit.createText(form.getBody(), "");
    textTo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    label = toolkit.createLabel(form.getBody(), "Subject: ", SWT.NULL);
    Text textSubject = toolkit.createText(form.getBody(), "");
    textSubject.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    label = toolkit.createLabel(form.getBody(), "Message: ", SWT.NULL);
    Text textMessage = toolkit.createText(form.getBody(), "");
    textMessage.setLayoutData(new GridData(GridData.FILL_BOTH));

    label = toolkit.createLabel(form.getBody(), "Option: ", SWT.NULL);
    Button buttonOption = toolkit.createButton(form.getBody(), "save a copy", SWT.CHECK);

    Button buttonClose = toolkit.createButton(form.getBody(), "Close", SWT.PUSH);
    GridData gridData = new GridData();
    gridData.horizontalSpan = 2;// ww  w. j  av a 2 s . co  m
    gridData.horizontalAlignment = GridData.END;
    buttonClose.setLayoutData(gridData);

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

    // Adds tool bar items.
    form.getToolBarManager().add(new Action("Send") {
        public void run() {
            System.out.println("Sending email ...");
        }
    });

    form.getToolBarManager().add(new Action("Cancel") {
        public void run() {
            System.out.println("Cancelled.");
        }
    });

    form.updateToolBar();

    return composite;
}

From source file:ShowProgress.java

/**
 * Creates the main window's contents//from  ww w .  j  av a 2 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, true));

    // Create the indeterminate checkbox
    final Button indeterminate = new Button(composite, SWT.CHECK);
    indeterminate.setText("Indeterminate");

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

    final Shell shell = parent.getShell();

    // Display the ProgressMonitorDialog
    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());
            }
        }
    });

    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, false));
    Button preserveCase = new Button(composite, SWT.CHECK);
    preserveCase.setText("&Preserve case");
    final TreeViewer tv = new TreeViewer(composite);
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput("root");

    preserveCase.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean preserveCase = ((Button) event.widget).getSelection();
            FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv.getLabelProvider();
            ftlp.setPreserveCase(preserveCase);
        }//from   ww  w  .  jav  a 2s  .  co m
    });
    return composite;
}