ImageCreateForLable.java Source code

Java tutorial

Introduction

Here is the source code for ImageCreateForLable.java

Source

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class ImageCreateForLable {

    public static void main(String[] args) {
        Image image;
        Image copy;
        Image disable;
        Image gray;

        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("Show Image Flags");

        image = new Image(display, "yourFile.gif");

        copy = new Image(display, image, SWT.IMAGE_COPY);

        disable = new Image(display, image, SWT.IMAGE_DISABLE);

        gray = new Image(display, image, SWT.IMAGE_GRAY);

        shell.setLayout(new FillLayout());

        // Create labels to hold each image
        new Label(shell, SWT.NONE).setImage(image);
        new Label(shell, SWT.NONE).setImage(copy);
        new Label(shell, SWT.NONE).setImage(disable);
        new Label(shell, SWT.NONE).setImage(gray);

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

        image.dispose();
        copy.dispose();
        disable.dispose();
        gray.dispose();

        display.dispose();

    }
}