- Composite背景渐变:
composite_main.addPaintListener(new PaintListener(){ @Override public void paintControl(PaintEvent arg0) { Rectangle rectangle = composite_main.getClientArea(); image = image == null ? new Image(display,1,Math.max(1, rectangle.height)): image; GC gc_main = new GC(image); gc_main.setBackground(SWTResourceManager.getColor(199, 215, 238)); gc_main.setForeground(SWTResourceManager.getColor(213, 231, 245)); gc_main.fillGradientRectangle(composite_main.getClientArea().x, composite_main.getClientArea().y, composite_main.getClientArea().width,composite_main.getClientArea().height,true); gc_main.dispose(); composite_main.setBackgroundImage(image);// } });
- Composite上控件背景颜色透明:
composite_main.setBackgroundMode(SWT.INHERIT_FORCE);
- Composite画圆角矩形:
container.addPaintListener(new PaintListener(){ @Override public void paintControl(PaintEvent arg0) { GC gc_container_1 = new GC(container); Color color_1 = new Color(Display.getDefault(),141,177,227); gc_container_1.setForeground(color_1); gc_container_1.setLineWidth(1); gc_container_1.drawRoundRectangle(2,2,x-20,isButtonBar == true?y-89:y-75,7,7); gc_container_1.dispose(); } });
- CLable背景颜色渐变:
label.setBackground(new Color[]{SWTResourceManager.getColor(207, 225, 245),SWTResourceManager.getColor(202, 225, 245)},new int[] {100}, true);
5. Composite背景渐变(随窗口大小而变)
infoComposite.addPaintListener(new PaintListener() {
private Image image_info_bg;
@Override
public void paintControl(PaintEvent arg0) {
Point point = infoComposite.getSize();
if(image_info_bg == null || image_info_bg.getBounds().height != point.y){
if(image_info_bg!=null&&!image_info_bg.isDisposed())
image_info_bg.dispose();
image_info_bg = new Image(infoComposite.getDisplay(),1,point.y);
}
GC gc_main = new GC(image_info_bg);
gc_main.setForeground(SWTResourceManager.getColor(120, 157, 210));
gc_main.setBackground(SWTResourceManager.getColor(66, 108, 180));
gc_main.fillGradientRectangle(infoComposite.getClientArea().x, infoComposite.getClientArea().y, infoComposite.getClientArea().width,infoComposite.getClientArea().height,true);
gc_main.dispose();
infoComposite.setBackgroundImage(image_info_bg);
}
});