Label label = new Label(shell, SWT.NONE); label.setText("Hello World!"); label.setBounds(20, 20, 100, 30);
Label label = new Label(shell, SWT.NONE); Image image = new Image(display, "image.png"); label.setImage(image); label.setBounds(0, 0, image.getBounds().width, image.getBounds().height);In this example, a new label widget is created without any text and added to a shell. An image is then added to the label using the setImage method. The setBounds method is called with the size of the image to ensure the label is the right size. The org.eclipse.swt.widgets package is part of the SWT (Standard Widget Toolkit) library, which is used for creating user interfaces in Java.