import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; 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 GraphicsSnippet { 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); // Colors Color red = new Color(Display.getDefault(), 255, 0, 0); Color blue = new Color(Display.getDefault(), 0, 0, 255); // Paint shell shell.addListener(SWT.Paint, event -> { GC gc = event.gc; // Draw red background on image gcImage.setBackground(red); gcImage.fillRectangle(0, 0, 128, 128); gc.drawImage(image, 0, 0); // Draw blue background on image and move x position gcImage.setBackground(blue); gcImage.fillRectangle(0, 0, 128, 128); gc.drawImage(image, 128, 0); }); shell.setSize(400, 400); shell.open(); while(!shell.isDisposed()) { if(!display.readAndDispatch()) display.sleep(); } display.dispose(); gcImage.dispose(); image.dispose(); red.dispose(); blue.dispose(); } }