Load existing image to panel by using Eclipse SWT

This post also assumes that you have a standalone Eclipse RCP application. You can find out how to make one here.

We may want to load an image to an application, this is also related with drawing method from GC class. We can first create an Image object and then use GC.drawImage() method to draw it on the panel. We can draw it in a different ratio from its original width and height. The GC.drawImage() method provide multiple options for programmers to use based on their requirement.

public void createPartControl(final Composite parent) {
 
	parent.setLayout(new FillLayout());
	parent.addPaintListener(new PaintListener() {
		public void paintControl(PaintEvent e) {
			Image image = new Image(e.display,"/home/xiaoran/Desktop/a.png"); 
		    GC gc = e.gc;			   
		    gc.drawImage(image, 0, 0);			 						
		}
	});
}
Category >> Rich Client Platform(RCP)  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>