简体   繁体   English

如何为SWT组合中的单个项目设置不同的颜色

[英]How to set different colors to individual items in an SWT Combo

I have a Combo dropdown in SWT and have been thinking of setting different colors to different items in my list based on some conditions. 我在SWT中有一个Combo下拉菜单,一直在考虑根据某些条件为列表中的不同项目设置不同的颜色。 I'll decide later (ie if the String has over 5 characters the item should have a red background otherwise it should be green) 我稍后再决定(即,如果String超过5个字符,则该项目应具有红色背景,否则应为绿色)

I managed to change the background of the whole Combo widget but have noticed no method to change the background for its individual items. 我设法更改了整个Combo小部件的背景,但是没有注意到没有方法更改其单个项目的背景。

Color colorGreenSWT = new Color(null, 0, 255, 0);
Combo combo = new Combo(comp, SWT.DROP_DOWN);
String[] languages = { "i", "it", "item", "items", "more_items" };
for (int i = 0; i < languages.length; i++)
    combo.add(languages[i]);
combo.setBackground(colorGreenSWT);

So is there any method to select the background color for each item in part? 那么,是否有任何方法可以为零件中的每个项目选择背景颜色?

Combo does not allow that. 组合不允许这样做。 The Nebula project has a TableCombo Widget [1] that might interest you. Nebula项目有一个TableCombo Widget [1],您可能会感兴趣。 Also SWT has an extended custom combo called CCombo that you might want to look at [2]. SWT还有一个扩展的自定义组合CCombo,您可能想看看[2]。

[1] https://eclipse.org/nebula/widgets/tablecombo/tablecombo.php [1] https://eclipse.org/nebula/widgets/tablecombo/tablecombo.php

[2] http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fcustom%2FCCombo.html [2] http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fcustom%2FCCombo.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM