Example usage for org.eclipse.swt.widgets Button computeSize

List of usage examples for org.eclipse.swt.widgets Button computeSize

Introduction

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

Prototype

public Point computeSize(int wHint, int hHint) 

Source Link

Document

Returns the preferred size of the receiver.

Usage

From source file:ControlEditorTestTwo.java

/**
 * Creates the main window's contents/*from  w  w w  .  j  a  v  a 2 s  .co  m*/
 * 
 * @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);
}

From source file:PrintKTableExample.java

protected Button addButton(boolean rightAdjusted, String text, String tip) {
    Button erg = new Button(guiButtonArea, SWT.PUSH);
    erg.setText(text);//from  ww w. j  a  v a 2s . c o  m
    erg.setToolTipText(tip);

    Point butPrefferedSize = erg.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    FormData fd = new FormData();
    fd.bottom = new FormAttachment(100, -3);

    if (butPrefferedSize.x > 70)
        fd.width = butPrefferedSize.x + 4;
    else
        fd.width = 70;
    fd.height = 24;
    erg.setLayoutData(fd);

    if (rightAdjusted) {
        if (guiLastRightBut == null)
            fd.right = new FormAttachment(100, -3);
        else
            fd.right = new FormAttachment(guiLastRightBut, -3);
        guiLastRightBut = erg;
    } else {
        if (guiLastLeftBut == null)
            fd.left = new FormAttachment(0, 3);
        else
            fd.left = new FormAttachment(guiLastLeftBut, 3);
        guiLastLeftBut = erg;
    }

    erg.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            onButton((Button) arg0.widget, ((Button) arg0.widget).getText());
        }
    });
    return erg;
}