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.Snippet69.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 69");
    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  ava 2 s  .com

    GC gc = new GC(text);
    FontMetrics fm = gc.getFontMetrics();
    double charWidth = fm.getAverageCharacterWidth();
    int width = text.computeSize((int) (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) {
    Display d = new Display();
    Shell s = new Shell(d);

    s.setSize(250, 250);/*from   w ww.j  av a 2 s  . co  m*/

    s.setText("A FormLayout Example");
    s.setLayout(new FormLayout());

    final Label l1 = new Label(s, SWT.RIGHT);
    l1.setText("First Name");
    FormData fd = new FormData();
    fd.top = new FormAttachment(10, 10);
    fd.left = new FormAttachment(0, 10);
    fd.bottom = new FormAttachment(30, 0);
    fd.right = new FormAttachment(40, 0);
    l1.setLayoutData(fd);

    final Label l2 = new Label(s, SWT.RIGHT);
    l2.setText("Last Name");
    fd = new FormData();
    fd.top = new FormAttachment(l1, 5);
    fd.left = new FormAttachment(0, 10);
    fd.bottom = new FormAttachment(40, 0);
    fd.right = new FormAttachment(40, 0);
    l2.setLayoutData(fd);

    final Text t1 = new Text(s, SWT.BORDER | SWT.SINGLE);
    fd = new FormData();
    fd.top = new FormAttachment(l1, 0, SWT.TOP);
    fd.left = new FormAttachment(l1, 10);
    t1.setLayoutData(fd);

    final Text t2 = new Text(s, SWT.BORDER | SWT.SINGLE);
    fd = new FormData();
    fd.top = new FormAttachment(l2, 0, SWT.TOP);
    fd.left = new FormAttachment(l2, 10);
    t2.setLayoutData(fd);

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

From source file:Snippet78.java

public static void main(String[] args) {

    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Label label1 = new Label(shell, SWT.BORDER);
    label1.setText("TEXT");
    final Label label2 = new Label(shell, SWT.BORDER);
    setDragDrop(label1);//from   w  w  w.ja  v  a2  s  .  c  o m
    setDragDrop(label2);
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ColorDialogButtonActionSetLabelBackground.java

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

    final Label colorLabel = new Label(shell, SWT.NONE);
    colorLabel.setText("Color");

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Color...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Color color = new Color(shell.getDisplay(), new RGB(0, 255, 0));
            ColorDialog dlg = new ColorDialog(shell);

            dlg.setRGB(colorLabel.getBackground().getRGB());
            dlg.setText("Choose a Color");

            RGB rgb = dlg.open();//  w w w.  j  a v  a  2s .  co  m
            if (rgb != null) {
                color.dispose();
                color = new Color(shell.getDisplay(), rgb);
                colorLabel.setBackground(color);
                color.dispose();
            }
        }
    });

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

    display.dispose();

}

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

public static void main(String[] args) {

    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 78");
    shell.setLayout(new FillLayout());
    final Label label1 = new Label(shell, SWT.BORDER);
    label1.setText("TEXT");
    final Label label2 = new Label(shell, SWT.BORDER);
    setDragDrop(label1);/*from w w  w .  j  a  v  a2 s  . c  o m*/
    setDragDrop(label2);
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 249");
    Rectangle clientArea = shell.getClientArea();
    shell.setBounds(clientArea.x + 10, clientArea.y + 10, 300, 200);
    // create the composite that the pages will share
    final Composite contentPanel = new Composite(shell, SWT.BORDER);
    contentPanel.setBounds(clientArea.x + 100, clientArea.y + 10, 190, 90);
    final StackLayout layout = new StackLayout();
    contentPanel.setLayout(layout);/*from  w  ww . j  a v  a 2  s .  c  o  m*/

    // create the first page's content
    final Composite page0 = new Composite(contentPanel, SWT.NONE);
    page0.setLayout(new RowLayout());
    Label label = new Label(page0, SWT.NONE);
    label.setText("Label on page 1");
    label.pack();

    // create the second page's content
    final Composite page1 = new Composite(contentPanel, SWT.NONE);
    page1.setLayout(new RowLayout());
    Button button = new Button(page1, SWT.NONE);
    button.setText("Button on page 2");
    button.pack();

    // create the button that will switch between the pages
    Button pageButton = new Button(shell, SWT.PUSH);
    pageButton.setText("Push");
    pageButton.setBounds(clientArea.x + 10, clientArea.y + 10, 80, 25);
    pageButton.addListener(SWT.Selection, event -> {
        pageNum = ++pageNum % 2;
        layout.topControl = pageNum == 0 ? page0 : page1;
        contentPanel.layout();
    });

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

From source file:StackLayoutSwitchComposites.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setBounds(10, 10, 300, 200);/*from  w  w w  .  jav a 2 s.  c  o m*/
    // create the composite that the pages will share
    final Composite contentPanel = new Composite(shell, SWT.BORDER);
    contentPanel.setBounds(100, 10, 190, 90);
    final StackLayout layout = new StackLayout();
    contentPanel.setLayout(layout);

    // create the first page's content
    final Composite page0 = new Composite(contentPanel, SWT.NONE);
    page0.setLayout(new RowLayout());
    Label label = new Label(page0, SWT.NONE);
    label.setText("Label on page 1");
    label.pack();

    // create the second page's content
    final Composite page1 = new Composite(contentPanel, SWT.NONE);
    page1.setLayout(new RowLayout());
    Button button = new Button(page1, SWT.NONE);
    button.setText("Button on page 2");
    button.pack();

    // create the button that will switch between the pages
    Button pageButton = new Button(shell, SWT.PUSH);
    pageButton.setText("Push");
    pageButton.setBounds(10, 10, 80, 25);
    pageButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            pageNum = ++pageNum % 2;
            layout.topControl = pageNum == 0 ? page0 : page1;
            contentPanel.layout();
        }
    });

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

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

public static void main(String[] args) {

    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("URLTransfer");
    shell.setLayout(new FillLayout());
    final Label label1 = new Label(shell, SWT.BORDER);
    label1.setText("http://www.eclipse.org");
    final Label label2 = new Label(shell, SWT.BORDER);
    setDragSource(label1);/*w w  w .j av  a 2s.c om*/
    setDropTarget(label2);
    shell.setSize(600, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {
    Display display = new Display();
    // Create the main window
    final Shell shell = new Shell(display);

    shell.setLayout(new GridLayout(2, false));

    final Label fontLabel = new Label(shell, SWT.NONE);
    fontLabel.setText("The selected font");

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Font...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            FontDialog dlg = new FontDialog(shell);
            Font font = null;/*from  w  w  w.  jav a  2s.  c o m*/
            Color color = null;

            if (font != null)
                dlg.setFontList(fontLabel.getFont().getFontData());
            if (color != null)
                dlg.setRGB(color.getRGB());

            if (dlg.open() != null) {
                if (font != null)
                    font.dispose();
                if (color != null)
                    color.dispose();

                font = new Font(shell.getDisplay(), dlg.getFontList());
                fontLabel.setFont(font);

                color = new Color(shell.getDisplay(), dlg.getRGB());
                fontLabel.setForeground(color);

                shell.pack();
            }
        }
    });

    shell.open();

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

From source file:MainClass.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sliders");
    shell.setSize(300, 200);//from w w w .  jav  a2 s .  c  o  m

    final Label label = new Label(shell, SWT.NONE);
    label.setText("Move the slider");
    label.setBounds(0, 20, 150, 15);

    final Slider slider = new Slider(shell, SWT.HORIZONTAL);
    slider.setBounds(0, 40, 200, 20);

    final Text text = new Text(shell, SWT.BORDER);
    text.setBounds(0, 100, 200, 25);

    slider.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            String outString = "Event: SWT.NONE";
            switch (event.detail) {
            case SWT.ARROW_DOWN:
                outString = "Event: SWT.ARROW_DOWN";
                break;
            case SWT.ARROW_UP:
                outString = "Event: SWT.ARROW_UP";
                break;
            case SWT.DRAG:
                outString = "Event: SWT.DRAG";
                break;
            case SWT.END:
                outString = "Event: SWT.END";
                break;
            case SWT.HOME:
                outString = "Event: SWT.HOME";
                break;
            case SWT.PAGE_DOWN:
                outString = "Event: SWT.PAGE_DOWN";
                break;
            case SWT.PAGE_UP:
                outString = "Event: SWT.PAGE_UP";
                break;
            }
            outString += " Position: " + slider.getSelection();
            text.setText(outString);
        }
    });

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