Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Shell;
Import Org.eclipse.swt.widgets.Composite;
Import Org.eclipse.swt.SWT;
Import Swing2swt.layout.FlowLayout;
Import Org.eclipse.swt.layout.FormLayout;
Import Org.eclipse.swt.layout.FormData;
Import org.eclipse.swt.layout.FormAttachment;
Import Org.eclipse.swt.widgets.Button;
Import org.eclipse.swt.graphics.*; The package to load the image with
public class Ima {
protected shell shell;
Private Device display;
/**
* Launch the application.
* @param args
*/
public static void Main (string[] args) {
try {
Ima window = new ima ();
window.open ();
} catch (Exception e) {
E.printstacktrace ();
}
}
/**
* Open the window.
*/
public void Open () {
Display display = Display.getdefault ();
Createcontents ();
Shell.open ();
Shell.layout ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
}
/**
* Create contents of the window.
*/
protected void createcontents () {
Shell = new Shell ();
Shell.setsize (685, 493);
Shell.settext ("SWT application");
Shell.setlayout (New Formlayout ());
Composite Composite = new Composite (Shell, SWT. NONE);
FormData fd_composite = new FormData ();
Fd_composite.top = new Formattachment (0, 10);
Fd_composite.left = new Formattachment (0, 10);
Fd_composite.bottom = new Formattachment (0, 436);
Fd_composite.right = new Formattachment (0, 657);
Composite.setlayoutdata (Fd_composite);
Composite.setlayout (New FlowLayout (Flowlayout.center, 5, 5));
Button Btnnewbutton = New button (composite, SWT. NONE);
Btnnewbutton.settext ("button");
Image Image=new Image (display, "c:\\users\\lenovo\\desktop\\8.jpg");
Image.setbackground (Display.getcurrent (). Getsystemcolor (SWT. color_red));
Btnnewbutton.setimage (image);
}
}
button implementation in Eclipse display image