演示代码如下: CLabelBorder.java package swt_jface.demo1; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class CLabelBorder { Display display = new Display(); Shell shell = new Shell(display); Image image = new Image(display, "C:/eclipse32.gif"); public CLabelBorder() { CLabel label1 = new CLabel(shell, SWT.SHADOW_OUT); label1.setText("SHADOW_OUT"); label1.setImage(image); label1.setBounds(10, 10, 150, 100); CLabel label2 = new CLabel(shell, SWT.SHADOW_IN); label2.setText("SHADOW_IN"); label2.setImage(image); label2.setBounds(170, 10, 150, 100); label2.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_GREEN), display.getSystemColor(SWT.COLOR_RED), display.getSystemColor(SWT.COLOR_BLUE), display.getSystemColor(SWT.COLOR_WHITE)}, new int[] {25, 50, 100}); CLabel label3 = new CLabel(shell, SWT.SHADOW_NONE); label3.setText("SHADOW_NONE"); label3.setBackground(image); label3.setBounds(330, 10, 150, 100); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } public static void main(String[] args) { new CLabelBorder(); } } CLabelGradientBG.java package swt_jface.demo1; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class CLabelGradientBG { Display display = new Display(); Shell shell = new Shell(display); Image image = new Image(display, "C:/eclipse32.gif"); public CLabelGradientBG() { CLabel labelGradientBg = new CLabel(shell, SWT.SHADOW_IN); labelGradientBg.setText("CLabel with gradient colored background"); labelGradientBg.setImage(image); labelGradientBg.setBounds(10, 10, 300, 100); labelGradientBg.setBackground( new Color[] { display.getSystemColor(SWT.COLOR_GREEN), display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_RED)}, new int[] { 50, 100 }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } public static void main(String[] args) { new CLabelGradientBG(); } } ImageButton.java package swt_jface.demo1; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class ImageButton { Display display = new Display(); Shell shell = new Shell(display); Image image = new Image(display, "C:/eclipse32.gif"); public ImageButton() { shell.setLayout(new RowLayout()); Button button = new Button(shell, SWT.PUSH); button.setBounds(10, 10, 200, 200); button.setImage(image); button.setText("button"); System.out.println(button.getImage()); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } public static void main(String[] args) { new ImageButton(); } }