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:org.eclipse.swt.snippets.Snippet108.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 108");
    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");
    ok.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("OK")));
    Button cancel = new Button(shell, SWT.PUSH);
    cancel.setText("Cancel");
    cancel.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("Cancel")));
    shell.setDefaultButton(cancel);/*from   ww  w.jav  a2  s .  co m*/
    shell.setLayout(new RowLayout());
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 278");
    shell.setBounds(10, 10, 300, 100);//from w ww  . j a v  a  2  s.  c  o m
    shell.setLayout(new FillLayout());
    final Label label = new Label(shell, SWT.NONE);
    label.setText("resize the Shell then hover over this Label");
    label.addListener(SWT.MouseEnter, event -> {
        Point requiredSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        Point labelSize = label.getSize();
        boolean fullyVisible = requiredSize.x <= labelSize.x && requiredSize.y <= labelSize.y;
        System.out.println("Label is fully visible: " + fullyVisible);
        label.setToolTipText(fullyVisible ? null : label.getText());
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 32");
    Label label = new Label(shell, SWT.NONE);
    label.setText("Can't find icon for .bmp");
    Image image = null;/*from   www  . java  2  s .  co m*/
    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:Snippet71.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.pack();// w  w  w.  java  2s .co  m
    shell.open();
    Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
    Label label = new Label(dialog, SWT.NONE);
    label.setText("Exit the application?");
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");

    FormLayout form = new FormLayout();
    form.marginWidth = form.marginHeight = 8;
    dialog.setLayout(form);
    FormData okData = new FormData();
    okData.top = new FormAttachment(label, 8);
    okButton.setLayoutData(okData);
    FormData cancelData = new FormData();
    cancelData.left = new FormAttachment(okButton, 8);
    cancelData.top = new FormAttachment(okButton, 0, SWT.TOP);
    cancelButton.setLayoutData(cancelData);

    dialog.setDefaultButton(okButton);
    dialog.pack();
    dialog.open();

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

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 344");
    shell.setLayout(new GridLayout(1, false));

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Click me");
    button.addSelectionListener(widgetSelectedAdapter(e -> {
        Shell shell2 = new Shell(SWT.TOOL | SWT.RESIZE | SWT.CLOSE | SWT.MAX);
        shell2.setLayout(new GridLayout(1, false));
        shell2.setText("Palette");
        Label l = new Label(shell2, SWT.LEFT);
        l.setText("This is a SWT.TOOL Shell");
        Point origin = shell.getLocation();
        origin.x += 100;/* w ww .ja va  2s.c  o m*/
        origin.y += 100;
        shell2.pack();
        shell2.open();
    }));

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

From source file:Snippet69.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.NONE | SWT.BORDER);
    label.setText("Name");
    Text text = new Text(shell, SWT.NONE);

    FormLayout layout = new FormLayout();
    layout.marginWidth = layout.marginHeight = 5;
    shell.setLayout(layout);/*from  w  w w .j a  v a  2  s .com*/

    GC gc = new GC(text);
    FontMetrics fm = gc.getFontMetrics();
    int charWidth = fm.getAverageCharWidth();
    int width = text.computeSize(charWidth * 8, SWT.DEFAULT).x;
    gc.dispose();
    FormData data = new FormData(width, SWT.DEFAULT);
    text.setLayoutData(data);
    data.left = new FormAttachment(label, 5);
    data.top = new FormAttachment(label, 0, SWT.CENTER);

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

From source file:MainClass.java

public static void main(String[] a) {

    Shell shell = new Shell(new Display());
    final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
    dialog.setText("Delete File");
    dialog.setSize(250, 150);// www.  j av a 2  s.  c  om

    final Button buttonOK = new Button(dialog, SWT.PUSH);
    buttonOK.setText("OK");
    buttonOK.setBounds(20, 55, 80, 25);

    Button buttonCancel = new Button(dialog, SWT.PUSH);
    buttonCancel.setText("Cancel");
    buttonCancel.setBounds(120, 55, 80, 25);

    final Label label = new Label(dialog, SWT.NONE);
    label.setText("Delete the file?");
    label.setBounds(20, 15, 100, 20);

    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            if (event.widget == buttonOK) {
                System.out.println("OK");
            } else {
                System.out.println("Cancel");
            }
            dialog.close();
        }
    };

    buttonOK.addListener(SWT.Selection, listener);
    buttonCancel.addListener(SWT.Selection, listener);

    dialog.open();

}

From source file:FormLayoutSingleLine.java

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

    Label label = new Label(shell, SWT.NONE | SWT.BORDER);
    label.setText("Name");

    Text text = new Text(shell, SWT.NONE);

    FormLayout layout = new FormLayout();
    layout.marginWidth = layout.marginHeight = 5;
    shell.setLayout(layout);//  ww w . jav a  2 s  .  c o  m

    FormData data = new FormData(200, SWT.DEFAULT);
    text.setLayoutData(data);
    data.left = new FormAttachment(label, 5);
    data.top = new FormAttachment(label, 0, SWT.CENTER);

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

From source file:DialogOKCancelFormLayout.java

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

    Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
    Label label = new Label(dialog, SWT.NONE);
    label.setText("Exit the application?");
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");

    FormLayout form = new FormLayout();
    form.marginWidth = form.marginHeight = 8;
    dialog.setLayout(form);//from   w ww  .  j a v a2 s . com
    FormData okData = new FormData();
    okData.top = new FormAttachment(label, 8);
    okButton.setLayoutData(okData);
    FormData cancelData = new FormData();
    cancelData.left = new FormAttachment(okButton, 8);
    cancelData.top = new FormAttachment(okButton, 0, SWT.TOP);
    cancelButton.setLayoutData(cancelData);

    dialog.setDefaultButton(okButton);
    dialog.pack();
    dialog.open();

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

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 71");
    shell.pack();//from w ww  . ja v a  2 s.co m
    shell.open();
    Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
    Label label = new Label(dialog, SWT.NONE);
    label.setText("Exit the application?");
    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");

    FormLayout form = new FormLayout();
    form.marginWidth = form.marginHeight = 8;
    dialog.setLayout(form);
    FormData okData = new FormData();
    okData.top = new FormAttachment(label, 8);
    okButton.setLayoutData(okData);
    FormData cancelData = new FormData();
    cancelData.left = new FormAttachment(okButton, 8);
    cancelData.top = new FormAttachment(okButton, 0, SWT.TOP);
    cancelButton.setLayoutData(cancelData);

    dialog.setDefaultButton(okButton);
    dialog.pack();
    dialog.open();

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