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

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

Introduction

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

Prototype


public void setAlignment(int alignment) 

Source Link

Document

Controls how text, images and arrows will be displayed in the receiver.

Usage

From source file:ButtonAlignment.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM);
    shell.setLayout(new FillLayout());

    Button button = new Button(shell, SWT.RIGHT);

    button.setText("text on the button");

    button.setAlignment(SWT.CENTER);

    shell.open();/*  ww  w  . jav  a2s . com*/
    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet366.java

private static void makeAlignGroup() {
    Group alignGroup = new Group(shell, SWT.None);
    alignGroup.setLayout(new RowLayout());
    alignGroup.setText("Alignment group");

    final AtomicInteger prevDir = new AtomicInteger(0);
    final Button alignmentButton = new Button(alignGroup, SWT.ARROW | SWT.UP);
    alignmentButton.addListener(SWT.MouseDown, event -> {
        switch (prevDir.get()) {
        case 0:/*from  www  . jav  a2 s .com*/
            alignmentButton.setAlignment(SWT.RIGHT);
            prevDir.set(1);
            break;
        case 1:
            alignmentButton.setAlignment(SWT.DOWN);
            prevDir.set(2);
            break;
        case 2:
            alignmentButton.setAlignment(SWT.LEFT);
            prevDir.set(3);
            break;
        case 3:
            alignmentButton.setAlignment(SWT.UP);
            prevDir.set(0);
        default:
            break;
        }
    });
}