zoukankan      html  css  js  c++  java
  • Enhancing the ComboWidget with Images(转载)

    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

    Update

    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 Dialog {
    8.      private List list;
    9.      /**
    10.       * @param parentShell
    11.       * @param list
    12.       */
    13.      protected SimpleDialog(Shell parentShell, List 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 Control createDialogArea(Composite parent) {
    21.          Composite comp = (Composite) super.createDialogArea(parent);
    22.          comp.setLayout(new GridLayout(2,true));
    23.          Label textLabel = new Label(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.          Iterator 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/
  • 相关阅读:
    2级搭建类203-Oracle 19c SI ASM 静默搭建(OEL7.7)
    2级搭建类EM-Oracle EMCC 13c Release 3 在 OEL 7.7 上的搭建
    1级搭建类112-Oracle 19c SI FS(CentOS 8)
    0级搭建类013-CentOS 8.x 安装
    List添加map,后添加的map覆盖前面的问题
    mysql插入数据报错1366
    oracle ora-12514解决办法
    easyUI 创建详情页dialog
    Server Tomcat v7.0 Server at localhost failed to start.
    maven项目启动报错;class path resource [com/ssm/mapping/] cannot be resolved to URL because it does not exist
  • 原文地址:https://www.cnblogs.com/wuhenke/p/2384425.html
Copyright © 2011-2022 走看看