Skip to content

Org.eclipse.swt.widgets.Label

Instances of this class represent a non-selectable user interface object that displays a string or image. When SEPARATOR is specified, displays a single vertical or horizontal line.

How to draw swt image?

Image myImage = new Image( display, "C:/sample_image.png" );
Label myLabel = new Label( shell, SWT.NONE );
myLabel.setImage( myImage );

Transparent Background

Instead you could try doing the following to get the same result.

  1. Create a label
  2. Assign an image to the label using a shell
  3. Then use "setText()" to write something on the label.

The Text will appear above the image. You will be able to see the image.

( Showing only relavent code ) Example of Label with text/image.

Image image = new Image(display, "c:\\picture.jpeg"); 
Shell shell = new Shell(SWT.NO_TRIM);
shell.setBounds(10,10,200,200);
shell.setBackgroundImage(image);
shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
Label label = new Label(shell, SWT.NONE);
label.setText("LAbel text here. ");

how to change colour of text in Label control?

Make sure you don't mix SWT and AWT colors, and if you build a Color object, make sure you dispose it. You want something like:

final Color myColor = new Color(getDisplay(), 102, 255, 102);
myLabel.setForeground(color);
myLabel.addDisposeListener(new DisposeListener() {
    public void widgetDisposed(DisposeEvent e)
    {
        myColor.dispose();
    }
});

Or you can just use the built-in system colors:

myLabel.setForeground(getDisplay().getSystemColor(SWT.COLOR_GREEN));

(Do not dispose the system colors.)

Favorite site