import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Image; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; public class LabelImageExample { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Image image = new Image(display, "path/to/image.png"); Label label = new Label(shell, SWT.NONE); label.setImage(image); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; public class LabelImageExample{ public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Composite composite = new Composite(shell, SWT.NONE); Image image = new Image(display, "path/to/image.png"); Label label = new Label(composite, SWT.NONE); label.setImage(image); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }This example sets an image for a label component within a composite. The package library used here is also org.eclipse.swt.