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/
  • 相关阅读:
    LeetCode 350. Intersection of Two Arrays II (两个数组的相交之二)
    LeetCode 349. Intersection of Two Arrays (两个数组的相交)
    LeetCode 290. Word Pattern (词语模式)
    LeetCode 266. Palindrome Permutation (回文排列)$
    34.Search for a Range
    spark连接mongodb
    NLPIR中文分词器的使用
    scala和maven整合实践
    Spark中的键值对操作-scala
    301.Remove Invalid Parentheses
  • 原文地址:https://www.cnblogs.com/wuhenke/p/2384425.html
Copyright © 2011-2022 走看看