博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Enhancing the Combo-Widget with Images(转载)
阅读量:5962 次
发布时间:2019-06-19

本文共 2367 字,大约阅读时间需要 7 分钟。

Probably you was already faced with the requirement to add small icons to your pulldowns. That looks very nice, but unfortunately there is no common SWT-Widget to realize this.

Fortunately the Eclipse-Framework is OpenSource and we can reprodruce the structure of a SWT-ComboBox. A Combo is not more than a text-field and a small button with an arrow. In addition is a event-handler implemented that shows a Composite as a tooltip with the entries of the "combo-list". We just have to take this class and change the structure of the content. We don't want to have a org.eclipse.swt.widgets.List, but a org.eclipse.swt.widgets.Table with multiple org.eclipse.swt.widgets.TableItems where you can specify an image. After adjusting the access-methods we have a new cool Widget, that has the same structure and methods like the "built-in"s. :)

Screenshot

image_combo.png

The ImageCombo in Action (as Widget in a JFace-Dialog).

Usage

  • Reference the Widget like all the other ones.

Update

  • (Thanks to Jeremy Dowdall)

Code-Example

The following snippet show the usage in a very simple JFace-Dialog.

JAVA:
  1. /**
  2. * Very Simple Dialog with {@link org.eclipse.swt.widgets.Label}
  3. * and a Combo that has the capability to show also icons.
  4. * @author Tom Seidel
  5. *
  6. */
  7. public
    class SimpleDialog
    extends
    {
  8.      
    private list;
  9.      
    /**
  10.       * @param parentShell
  11.       * @param list
  12.       */
  13.      
    protected SimpleDialog
    (Shell parentShell, list
    )
    {
  14.          super
    (parentShell
    );
  15.          
    this.
    list = list;
  16.      
    }
  17.      
    /* (non-Javadoc)
  18.       * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
  19.       */
  20.      
    protected createDialogArea
    ( parent
    )
    {
  21.           comp =
    (
    ) super.
    createDialogArea
    (parent
    );
  22.          comp.
    setLayout
    (
    new
    (
    2,
    true
    )
    );
  23.           textLabel =
    new
    (comp,SWT.
    NONE
    );
  24.          GridData gd =
    new GridData
    (SWT.
    BEGINNING, SWT.
    CENTER,
    false,
    false
    );
  25.          gd.
    widthHint =
    80;
  26.          textLabel.
    setLayoutData
    (gd
    );
  27.          textLabel.
    setText
    (
    "Your choice:"
    );
    //$NON-NLS-1$
  28.          ImageCombo combo =
    new ImageCombo
    (comp, SWT.
    READ_ONLY | SWT.
    BORDER
    );
  29.           iter =
    this.
    list.
    iterator
    (
    );
  30.          
    while
    (iter.
    hasNext
    (
    )
    )
    {
  31.              AbstractBaseElement element =
    (AbstractBaseElement
    ) iter.
    next
    (
    );
  32.              
    // add text and image to the combo.
  33.              combo.
    add
    (element.
    getId
    (
    ),ImagecontributionPlugin.
    getDefault
    (
    )
  34.                  .
    getImage
    (ImageContributor.
    getImageIdByObject
    (element
    )
    )
    );
  35.          
    }
  36.          combo.
    setLayoutData
    (gd
    );
  37.        
    return comp;
  38.    
    }
  39. }
转载:
http://www.richclient2.de/2006_03_03/enhancing-the-combo-widget-with-images/
你可能感兴趣的文章
校验表单如何摆脱 if else ?
查看>>
<气场>读书笔记
查看>>
Centos下基于Hadoop安装Spark(分布式)
查看>>
3D地图的定时高亮和点击事件(基于echarts)
查看>>
mysql开启binlog
查看>>
设置Eclipse编码方式
查看>>
分布式系统唯一ID生成方案汇总【转】
查看>>
并查集hdu1232
查看>>
Mysql 监视工具
查看>>
从前后端分离到GraphQL,携程如何用Node实现?\n
查看>>
Linux Namespace系列(09):利用Namespace创建一个简单可用的容器
查看>>
博客搬家了
查看>>
Python中使用ElementTree解析xml
查看>>
jquery 操作iframe、frameset
查看>>
解决vim中不能使用小键盘
查看>>
jenkins权限管理,实现不同用户组显示对应视图views中不同的jobs
查看>>
我的友情链接
查看>>
CentOS定时同步系统时间
查看>>
批量删除用户--Shell脚本
查看>>
Eclipse Java @Override 报错
查看>>