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:ViewFormExample.java

public ViewFormExample() {
    shell.setLayout(new FillLayout());

    final ViewForm viewForm = new ViewForm(shell, SWT.BORDER);
    Label label = new Label(viewForm, SWT.NULL);
    label.setText("Top center");

    viewForm.setTopCenter(label);// w  w  w . j a va 2s.  c o m

    shell.setSize(400, 200);
    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:MouseListenerExample.java

public MouseListenerExample() {
    d = new Display();
    s = new Shell(d);

    s.setSize(250, 200);//  w w w  .  j  a  v a  2  s  .com

    s.setText("A MouseListener Example");
    s.open();

    s.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            Label l = new Label(s, SWT.FLAT);
            l.setText("Mouse Button Down at:" + e.x + " " + e.y);
            l.setBounds(e.x, e.y, 150, 15);

        }

        public void mouseUp(MouseEvent e) {
            Label l = new Label(s, SWT.FLAT);
            l.setText("Mouse Button up at:" + e.x + " " + e.y);
            l.setBounds(e.x, e.y, 150, 15);
        }

        public void mouseDoubleClick(MouseEvent e) {

        }
    });

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

From source file:LabelWrap.java

public LabelWrap() {
    Display display = new Display();
    Shell shell = new Shell(display);

    String text = "Professional Java Interfaces With SWT/JFace, by Jack Li Guojie";

    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);//  www  .  ja va 2  s .  c o m
    labelWrap.setBounds(120, 10, 100, 100);

    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:MainClass.java

public void createControl(Composite parent) {
    Label label = new Label(parent, SWT.CENTER);
    label.setText("Thanks!");
    setControl(label);//from ww  w  .  j  a  va2 s. co m
}

From source file:FormLayoutExample.java

FormLayoutExample() {
    d = new Display();
    s = new Shell(d);
    s.setSize(250, 250);//w w w .j  a va  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:MainClass.java

public void createLabel(Composite c, int style, String text) {

    Label l = new Label(c, style);

    l.setText(text);
}

From source file:ScaleExample.java

public ScaleExample() {
    shell.setLayout(new GridLayout(1, true));

    Label label = new Label(shell, SWT.NULL);
    label.setText("Volume:");

    scale = new Scale(shell, SWT.VERTICAL);
    scale.setBounds(0, 0, 40, 200);//  w w  w  .  j  a va2 s  .  com
    scale.setMaximum(20);
    scale.setMinimum(0);
    scale.setIncrement(1);
    scale.setPageIncrement(5);

    scale.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            int perspectiveValue = scale.getMaximum() - scale.getSelection() + scale.getMinimum();
            value.setText("Vol: " + perspectiveValue);
        }
    });

    value = new Text(shell, SWT.BORDER | SWT.SINGLE);

    value.setEditable(false);
    scale.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    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:RadioButtons.java

public RadioButtons() {
    Display display = new Display();
    Shell shell = new Shell(display);

    shell.setLayout(new RowLayout());

    Label label = new Label(shell, SWT.NULL);
    label.setText("Gender: ");
    label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));

    Button femaleButton = new Button(shell, SWT.RADIO);
    femaleButton.setText("F");

    Button maleButton = new Button(shell, SWT.RADIO);
    maleButton.setText("M");

    label = new Label(shell, SWT.NULL);
    label.setText("  Title: ");
    label.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));

    Composite composite = new Composite(shell, SWT.NULL);
    composite.setLayout(new RowLayout());

    Button mrButton = new Button(composite, SWT.RADIO);
    mrButton.setText("Mr.");
    Button mrsButton = new Button(composite, SWT.RADIO);
    mrsButton.setText("Mrs.");
    Button msButton = new Button(composite, SWT.RADIO);
    msButton.setText("Ms.");
    Button drButton = new Button(composite, SWT.RADIO);
    drButton.setText("Dr.");

    shell.pack();//from  w w  w  .  j a v  a2  s. c o m
    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();/*  w  w w.ja  va  2  s.  co m*/

    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:ChooseColor.java

/**
 * Creates the window contents/*from  w w  w. ja v a  2 s.  c  o  m*/
 * 
 * @param shell the parent shell
 */
private void createContents(final Shell shell) {
    shell.setLayout(new GridLayout(2, false));

    // Start with Celtics green
    color = new Color(shell.getDisplay(), new RGB(0, 255, 0));

    // Use a label full of spaces to show the color
    final Label colorLabel = new Label(shell, SWT.NONE);
    colorLabel.setText("                              ");
    colorLabel.setBackground(color);

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Color...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            ColorDialog dlg = new ColorDialog(shell);

            // Set the selected color in the dialog from
            // user's selected color
            dlg.setRGB(colorLabel.getBackground().getRGB());

            // Change the title bar text
            dlg.setText("Choose a Color");

            // Open the dialog and retrieve the selected color
            RGB rgb = dlg.open();
            if (rgb != null) {
                // Dispose the old color, create the
                // new one, and set into the label
                color.dispose();
                color = new Color(shell.getDisplay(), rgb);
                colorLabel.setBackground(color);
            }
        }
    });
}