`

利用SWT内部的图标

阅读更多
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class CLabelSample {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("CLabel");

		RowLayout layout = new RowLayout(SWT.HORIZONTAL);
		layout.marginWidth = 10;
		shell.setLayout(layout);

		CLabel cl = new CLabel(shell, SWT.LEFT);
		cl.setText("这是一个带图标的自定义标签");
		cl.setImage(display.getSystemImage(SWT.ICON_INFORMATION));

		cl.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), 
				display.getSystemColor(SWT.COLOR_BLUE),
				display.getSystemColor(SWT.COLOR_WHITE), 
				display.getSystemColor(SWT.COLOR_WHITE)},
				new int[] {25, 50, 100});

		shell.layout();
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();

	}

}

 效果图:



 这里利用了SWT中自带的SWT.ICON_INFORMATION图标。写一些测试用例时可以尽量采用这种方法。

  • 大小: 6.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics