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

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

Introduction

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

Prototype

public void setText(String text) 

Source Link

Document

Sets the receiver's text.

Usage

From source file:MainClass.java

public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sash One");

    // The SWT.BORDER style
    Decorations d = new Decorations(shell, SWT.CLOSE);
    d.setLayoutData(new GridData(GridData.FILL_BOTH));
    d.setLayout(new FillLayout());
    Label l = new Label(d, SWT.CENTER);
    l.setText("SWT.CLOSE");

    d.setBounds(20, 20, 100, 100);//from w  w w. ja va  2  s.c  om

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:WrapStyleLabel.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);

    String text = "This is a long long long long long long long text.";

    Label labelNoWrap = new Label(shell, SWT.BORDER);
    labelNoWrap.setText(text);
    labelNoWrap.setBounds(10, 10, 100, 100);

    Label labelWrap = new Label(shell, SWT.WRAP | SWT.BORDER);
    labelWrap.setText(text);/*from   ww w  .  ja  v  a  2  s  .  c  o m*/
    labelWrap.setBounds(120, 10, 100, 100);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}

From source file:LabelTextImageAlignment.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());

    Label label = new Label(shell, SWT.BORDER | SWT.RIGHT);
    label.setText("text on the label");

    shell.open();/*w w w. j av  a2 s  .c o  m*/
    // 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:Snippet108.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.NONE);
    label.setText("Enter your name:");
    Text text = new Text(shell, SWT.BORDER);
    text.setLayoutData(new RowData(100, SWT.DEFAULT));
    Button ok = new Button(shell, SWT.PUSH);
    ok.setText("Ok");
    Button cancel = new Button(shell, SWT.PUSH);
    cancel.setText("Cancel");
    shell.setDefaultButton(cancel);/*from ww w  . ja v  a 2 s  .  co  m*/
    shell.setLayout(new RowLayout());
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:AccessibleControlListenerAdding.java

License:asdf

public static void main(String[] args) {
    final Display display = new Display();

    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Label label = new Label(shell, SWT.NONE);
    label.setText("asdf");

    Accessible accessible = label.getAccessible();
    accessible.addAccessibleControlListener(new AccessibleControlAdapter() {
        public void getState(AccessibleControlEvent e) {
            super.getState(e);
            System.out.println("AccessibleControlListener");
        }//from  w w  w .  j  a v a2 s  .  c o  m
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }

    display.dispose();
}

From source file:LabelShadowInOut.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());

    Label label = new Label(shell, SWT.BORDER | SWT.SHADOW_OUT);
    label.setText("text on the label");

    shell.open();//from   ww  w.ja va  2s  . c om
    // 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:MainClass.java

public static void main(String[] a) {
    Display d = new Display();
    Shell s = new Shell(d);

    s.setSize(250, 250);/*www  .  ja v a  2 s  . c  om*/

    s.setText("A GridLayout Example");
    GridLayout gl = new GridLayout();
    gl.numColumns = 3;
    s.setLayout(gl);
    Label l1 = new Label(s, SWT.BORDER);
    l1.setText("Column One");
    final Label l2 = new Label(s, SWT.BORDER);
    l2.setText("Column Two");
    final Label l3 = new Label(s, SWT.BORDER);
    l3.setText("Column Three");
    Text t1 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t2 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t3 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t4 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t5 = new Text(s, SWT.SINGLE | SWT.BORDER);
    Text t6 = new Text(s, SWT.SINGLE | SWT.BORDER);

    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:AccessibleListenerAdding.java

License:asdf

public static void main(String[] args) {
    final Display display = new Display();

    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Label label = new Label(shell, SWT.NONE);
    label.setText("asdf");

    Accessible accessible = label.getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter() {
        public void getName(AccessibleEvent e) {
            super.getName(e);
            e.result = "Speak this instead of the text";
            System.out.println("Accessible");

        }/*from w  w  w.j a  va2  s.c om*/
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }

    display.dispose();
}

From source file:Snippet32.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.NONE);
    label.setText("Can't find icon for .bmp");
    Image image = null;/* w w  w .  jav  a2  s  . c om*/
    Program p = Program.findProgram(".bmp");
    if (p != null) {
        ImageData data = p.getImageData();
        if (data != null) {
            image = new Image(display, data);
            label.setImage(image);
        }
    }
    label.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (image != null)
        image.dispose();
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 276");
    shell.setBounds(200, 200, 400, 400);
    Label label = new Label(shell, SWT.NONE);
    label.setText("click in shell to print display-relative coordinate");
    Listener listener = event -> {//  w  ww  .j  a va  2 s .  c  om
        Point point = new Point(event.x, event.y);
        System.out.println(display.map((Control) event.widget, null, point));
    };
    shell.addListener(SWT.MouseDown, listener);
    label.addListener(SWT.MouseDown, listener);
    Rectangle clientArea = shell.getClientArea();
    label.setLocation(clientArea.x, clientArea.y);
    label.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}