Draw2d Label

在Draw2d中,IFigure对象代表图形,IFigure对象还能包含其他的IFigure对象,所有的IFigure对象组合成用户指定的图形
通常用户可以继承Figure类实现自己的图形。Figure实现了IFigure接口
我下面写了个实例,实现了一个Figure,并设置边框为 LineBorder(边框类似为连线),而且还给它加了颜色,好像是淡绿色,对颜色没啥研究,另外还添加了以个Label作为显示的Figure,并设置为Label的现实文字和文字对齐方式,以及Figure的布局

  1. package com.heming.table.editor.figure;   
  2.   
  3. import org.eclipse.draw2d.ColorConstants;   
  4. import org.eclipse.draw2d.Figure;   
  5. import org.eclipse.draw2d.FlowLayout;   
  6. import org.eclipse.draw2d.Label;   
  7. import org.eclipse.draw2d.LineBorder;   
  8. import org.eclipse.draw2d.PositionConstants;   
  9. import org.eclipse.swt.graphics.Image;   
  10.   
  11. /**  
  12.  * Figure功能  
  13.  * @author 何明  
  14.  *  
  15.  */  
  16. public class KCGCommonFigure extends Figure {   
  17.   
  18.     //在Figure中添加标签(标签也是Figure)   
  19.     protected Label label = new Label();   
  20.        
  21.     public KCGCommonFigure(String fieldLabel, Image typeIcon){   
  22.            
  23.         //设置背景色   
  24.         setBackgroundColor(ColorConstants.tooltipBackground);   
  25.            
  26.         //设置前景色   
  27.         setForegroundColor(ColorConstants.tooltipForeground);   
  28.            
  29.         //设置Figure的边框,并给边框加上颜色   
  30.         setBorder(new LineBorder(ColorConstants.cyan));   
  31.            
  32.         //设置label中文字的对齐方式   
  33.         label.setTextAlignment(PositionConstants.LEFT);   
  34.            
  35.         //设置label的图标   
  36.         label.setIcon(typeIcon);   
  37.            
  38.         //设置Figure的布局方式   
  39.         setLayoutManager(new FlowLayout());   
  40.            
  41.         //把label添加到Figure中   
  42.         add(label);   
  43.            
  44.         //设置label的显示文字   
  45.         setLabelText(fieldLabel);   
  46.   
  47.     }   
  48.   
  49.     private void setLabelText(String fieldLabel) {   
  50.        
  51.         label.setText(fieldLabel);   
  52.            
  53.     }   
  54.        
  55. }  
接下来就是测试了
在写这篇文章之前,写了个HelloWorld,咱们就拿它来测试了
只需要将
  1. IFigure label = new Label("Hello World");   
  2.            
  3.            
  4.         lws.setContents(label);  
换成
  1. KCGCommonFigure figure = new KCGCommonFigure("Figure Demo",SWTResourceManager.getImage("icons/methpub_obj.gif"));   
  2.            
  3.         lws.setContents(figure);  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值