Swt combobox name/key pair

痞子三分冷 提交于 2019-12-04 05:58:29
countcb

Maybe you can use the setData(String key, Object value) method of the combobox to achive what you want.

Example:

Combo box = new Combo(parent, SWT.DROP_DOWN);
String s = "Item 1";
box.add(s);
box.setData(s, "Some other info or object here");
s = "Item 2";
box.add(s);
box.setData(s, "This is item two");

String value = (String)box.getData("Item 2");
// value is now "This is item two"

Note that the getData method returns an Object. So you have to cast it to the Type that you set with the setData method.

Because of this you are not limited to set Strings as your values. You can set any Object you want as the value with the setData method. Just make sure you cast correctly when you receive the data again with the getData method.

Edit: BTW, you can use the setData and getData methods on any SWT widget.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!