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

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

Introduction

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

Prototype

public void setAlignment(int alignment) 

Source Link

Document

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

Usage

From source file:GroupExamples.java

public GroupExamples() {

    Group group0 = new Group(shell, SWT.NULL);
    group0.setLayout(new FillLayout());
    Label label = new Label(group0, SWT.NULL);
    label.setAlignment(SWT.CENTER);
    label.setText("a group without title.");

    Group group1 = new Group(shell, SWT.NULL);
    group1.setText("SWT.NULL");

    Group group2 = new Group(shell, SWT.SHADOW_ETCHED_IN);
    group2.setText("SWT.SHADOW_ETCHED_IN");

    Group group3 = new Group(shell, SWT.SHADOW_ETCHED_OUT);
    group3.setText("SWT.SHADOW_ETCHED_OUT");

    Group group4 = new Group(shell, SWT.SHADOW_IN);
    group4.setText("SWT.SHADOW_IN");

    Group group5 = new Group(shell, SWT.SHADOW_OUT);
    group5.setText("SWT.SHADOW_OUT");

    Group[] groups = new Group[] { group0, group1, group2, group3, group4, group5 };

    for (int i = 0; i < groups.length; i++) {
        groups[i].setBounds(10, 10 + i * 50, 300, 40);
    }/* w  w  w .ja  v  a 2s  . com*/

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // 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:ProgressBarExamples.java

public ProgressBarExamples() {
    init();/*from w w  w.ja va2s.  c  om*/

    ProgressBar pb1 = new ProgressBar(shell, SWT.NULL);
    final ProgressBar pb2 = new ProgressBar(shell, SWT.SMOOTH);
    ProgressBar pb3 = new ProgressBar(shell, SWT.INDETERMINATE);

    //      pb2.addPaintListener(new PaintListener() {
    //         public void paintControl(PaintEvent e) {
    //            Point point = pb2.getSize();
    //            
    //            Font font = new Font(shell.getDisplay(),"Courier",10,SWT.BOLD);
    //            e.gc.setFont(font);
    //            e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    //            
    //            FontMetrics fontMetrics = e.gc.getFontMetrics();
    //            int stringWidth = fontMetrics.getAverageCharWidth() * 4;
    //            int stringHeight = fontMetrics.getHeight();
    //            
    //            e.gc.drawString("60%", (point.x-stringWidth)/2 , (point.y-stringHeight)/2, true);
    //            font.dispose();
    //         }
    //      });

    pb1.setSelection(60);
    pb2.setSelection(60);

    pb1.setBounds(100, 10, 200, 20);
    pb2.setBounds(100, 40, 200, 20);
    //pb3.setBounds(100, 70, 200, 20);

    Label label = new Label(shell, SWT.NULL);
    label.setText("(default)");
    Label label2 = new Label(shell, SWT.NULL);
    label2.setText("SWT.SMOOTH");

    label.setAlignment(SWT.RIGHT);
    label2.setAlignment(SWT.RIGHT);

    label.setBounds(10, 10, 80, 20);
    label2.setBounds(10, 40, 80, 20);

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // 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:WordJumbles.java

public WordJumbles(String word) {
    this.word = word;

    shell.setText("Word Jumbles");

    labelsRowOne = new Label[word.length()];
    labelsRowTwo = new Label[word.length()];

    int width = 40;

    // In the production version, you need to implement random permutation
    // generation.
    // Apache Jakarta Commons provides this function, see
    // org.apache.commons.math.random.RandomDataImpl
    int[] randomPermutation = { 5, 2, 6, 3, 1, 4, 0 };

    for (int i = 0; i < word.length(); i++) {
        final Label labelRowOne = new Label(shell, SWT.BORDER);
        labelsRowOne[i] = labelRowOne;//from  w ww  .  j a  v  a2 s  .c o m
        labelRowOne.setBounds(10 + width * i, 10, width - 5, width - 5);
        labelRowOne.setFont(font);
        labelRowOne.setText(word.charAt(randomPermutation[i]) + "");
        labelRowOne.setAlignment(SWT.CENTER);

        setDragSource(labelRowOne);
        //setDropTarget(labelRowOne);

        final Label labelRowTwo = new Label(shell, SWT.BORDER);
        labelsRowTwo[i] = labelRowTwo;
        labelRowTwo.setBounds(10 + width * i, 20 + width, width - 5, width - 5);
        labelRowTwo.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
        labelRowTwo.setFont(font);
        labelRowTwo.setAlignment(SWT.CENTER);

        setDragSource(labelRowTwo);
        //setDropTarget(labelRowTwo);
    }

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}