import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class ImageCreateCode {
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Label label = new Label(shell,SWT.NONE);
label.setImage(getCheckedImage(display));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
static Image getCheckedImage(Display display) {
Image image = new Image(display, 16, 16);
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
gc.fillOval(0, 0, 16, 16);
gc.setForeground(display.getSystemColor(SWT.COLOR_DARK_GREEN));
gc.drawLine(0, 0, 16, 16);
gc.drawLine(16, 0, 0, 16);
gc.dispose();
return image;
}
}
|