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

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

Introduction

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

Prototype

public Label(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

From source file:SashFormExample.java

public SashFormExample() {

    shell.setLayout(new FillLayout());

    sashForm = new SashForm(shell, SWT.HORIZONTAL);

    Text text1 = new Text(sashForm, SWT.CENTER);
    text1.setText("Text in pane #1");
    Text text2 = new Text(sashForm, SWT.CENTER);
    text2.setText("Text in pane #2");

    sashForm2 = new SashForm(sashForm, SWT.VERTICAL);

    final Label labelA = new Label(sashForm2, SWT.BORDER | SWT.CENTER);
    labelA.setText("Label in pane A");
    final Label labelB = new Label(sashForm2, SWT.BORDER | SWT.CENTER);
    labelB.setText("Label in pane B");

    text1.addControlListener(new ControlListener() {
        public void controlMoved(ControlEvent e) {
        }/*from   www . ja  va 2 s .  c o  m*/

        public void controlResized(ControlEvent e) {
            System.out.println("Resized");

        }
    });

    sashForm.setWeights(new int[] { 1, 2, 3 });

    labelA.addMouseListener(new MouseListener() {
        public void mouseDoubleClick(MouseEvent e) {
            if (sashForm2.getMaximizedControl() == labelA)
                sashForm2.setMaximizedControl(null);
            else
                sashForm2.setMaximizedControl(labelA);
        }

        public void mouseDown(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }
    });

    shell.setSize(450, 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:org.eclipse.swt.examples.helloworld.HelloWorld4.java

public Shell open(Display display) {
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Label label = new Label(shell, SWT.CENTER);
    label.setText(resHello.getString("Hello_world"));
    shell.pack();/* ww w .j a  va 2  s .  c  o m*/
    shell.open();
    return shell;
}

From source file:ChooseColor.java

/**
 * Creates the window contents/*  w ww  . ja  va  2s  .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);
            }
        }
    });
}

From source file:GetInput.java

/**
 * Creates the main window's contents/*  w  w  w  .ja  va2s  . c  o  m*/
 * 
 * @param parent the main window
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    // Create a label to display what the user typed in
    final Label label = new Label(composite, SWT.NONE);
    label.setText("This will display the user input from InputDialog");

    // Create the button to launch the error dialog
    Button show = new Button(composite, SWT.PUSH);
    show.setText("Get Input");
    show.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "", "Enter 5-8 characters",
                    label.getText(), new LengthValidator());
            if (dlg.open() == Window.OK) {
                // User clicked OK; update the label with the input
                label.setText(dlg.getValue());
            }
        }
    });

    parent.pack();
    return composite;
}

From source file:TemperatureConverterJFace.java

protected Control createContents(Composite parent) {
    getShell().setText("JFace Temperature Converter");

    Composite converterComposite = new Composite(parent, SWT.NULL);

    converterComposite.setLayout(new GridLayout(4, false));

    fahrenheitLabel = new Label(converterComposite, SWT.NULL);
    fahrenheitLabel.setText("Fahrenheit: ");

    fahrenheitValue = new Text(converterComposite, SWT.SINGLE | SWT.BORDER);

    celsiusLabel = new Label(converterComposite, SWT.NULL);
    celsiusLabel.setText("Celsius: ");

    celsiusValue = new Text(converterComposite, SWT.SINGLE | SWT.BORDER);

    ModifyListener listener = new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            valueChanged((Text) e.widget);
        }//from w w  w . j a  va  2  s .c  om
    };

    fahrenheitValue.addModifyListener(listener);
    celsiusValue.addModifyListener(listener);

    return converterComposite;
}

From source file:ImageRegistryTest.java

/**
 * Creates the window's contents/*from   w ww. ja  va  2  s  . co m*/
 * 
 * @param parent the parent composite
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new FillLayout());

    // Put the images in the registry
    ImageRegistry ir = new ImageRegistry();
    ir.put(ONE, ImageDescriptor.createFromFile(ImageRegistryTest.class, "java2s.gif"));
    ir.put(TWO, ImageDescriptor.createFromFile(ImageRegistryTest.class, "java2s.gif"));
    ir.put(THREE, ImageDescriptor.createFromFile(ImageRegistryTest.class, "java2s.gif"));

    // Create the labels and add the images
    Label label = new Label(composite, SWT.NONE);
    label.setImage(ir.get(ONE));
    label = new Label(composite, SWT.NONE);
    label.setImage(ir.get(TWO));
    label = new Label(composite, SWT.NONE);
    label.setImage(ir.get(THREE));

    getShell().pack();

    return composite;
}

From source file:org.eclipse.swt.examples.helloworld.HelloWorld3.java

public Shell open(Display display) {
    final Shell shell = new Shell(display);
    final Label label = new Label(shell, SWT.CENTER);
    label.setText(resHello.getString("Hello_world"));
    label.pack();/*  w w w.  java  2  s. co  m*/
    shell.addControlListener(
            ControlListener.controlResizedAdapter(e -> label.setBounds(shell.getClientArea())));
    shell.pack();
    shell.open();
    return shell;
}

From source file:MultipleListenersExample.java

/**
 * Create the main window's contents// ww w  .ja  v  a 2  s  .c  o  m
 * @param shell the main window
 */
private void createContents(Shell shell) {
    shell.setLayout(new GridLayout(3, true));

    // Create the label and input box for Fahrenheit
    new Label(shell, SWT.LEFT).setText("Fahrenheit:");
    fahrenheit = new Text(shell, SWT.BORDER);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    fahrenheit.setLayoutData(data);

    // Set the context-sensitive help
    fahrenheit.setData("Type a temperature in Fahrenheit");

    // Add the listeners
    fahrenheit.addHelpListener(this);
    fahrenheit.addVerifyListener(this);
    fahrenheit.addModifyListener(this);

    // Create the label and input box for Celsius
    new Label(shell, SWT.LEFT).setText("Celsius:");
    celsius = new Text(shell, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    celsius.setLayoutData(data);

    // Set the context-sensitive help
    celsius.setData("Type a temperature in Celsius");

    // Add the listeners
    celsius.addHelpListener(this);
    celsius.addVerifyListener(this);
    celsius.addModifyListener(this);

    // Create the area for help
    help = new Label(shell, SWT.LEFT | SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 3;
    help.setLayoutData(data);
}

From source file:RegistryTest.java

/**
 * Creates the window's contents//from   w  ww  .  j a  v  a 2s .  c o m
 * 
 * @param parent the parent composite
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new FillLayout(SWT.VERTICAL));

    // Set up the registries
    CR = new ColorRegistry();
    CR.addListener(this);

    FR = new FontRegistry();
    FR.addListener(this);

    // Create the label
    label = new Label(composite, SWT.CENTER);
    label.setText("Hello from JFace");

    // Create the randomize button
    Button button = new Button(composite, SWT.PUSH);
    button.setText("Randomize");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            CR.put(FOREGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255),
                    (int) (Math.random() * 255)));
            CR.put(BACKGROUND, new RGB((int) (Math.random() * 255), (int) (Math.random() * 255),
                    (int) (Math.random() * 255)));
            FontData fontData = new FontData("Times New Roman", (int) (Math.random() * 72), SWT.BOLD);
            FR.put(FONT, new FontData[] { fontData });
        }
    });
    return composite;
}

From source file:InputDialog.java

private void createContents(final Shell shell) {
    shell.setLayout(new GridLayout(2, true));

    Label label = new Label(shell, SWT.NONE);
    label.setText(message);// ww  w. j a va  2  s  . com
    GridData data = new GridData();
    data.horizontalSpan = 2;
    label.setLayoutData(data);

    final Text text = new Text(shell, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    text.setLayoutData(data);

    Button ok = new Button(shell, SWT.PUSH);
    ok.setText("OK");
    data = new GridData(GridData.FILL_HORIZONTAL);
    ok.setLayoutData(data);
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            input = text.getText();
            shell.close();
        }
    });

    Button cancel = new Button(shell, SWT.PUSH);
    cancel.setText("Cancel");
    data = new GridData(GridData.FILL_HORIZONTAL);
    cancel.setLayoutData(data);
    cancel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            input = null;
            shell.close();
        }
    });

    shell.setDefaultButton(ok);
}