import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class GraphicsSnippet2 { public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); // Create image and GC for drawing Image image = new Image(display, 128, 128); GC gcImage = new GC(image); // Paint shell shell.addListener(SWT.Paint, event -> { GC gc = event.gc; gcImage.fillRectangle(0, 0, 128, 128); gc.drawImage(image, 0, 0); }); shell.setSize(400, 400); shell.open(); while(!shell.isDisposed()) { if(!display.readAndDispatch()) display.sleep(); } display.dispose(); gcImage.dispose(); image.dispose(); } }