SWT Combo/List only allows to add item value, but no key
Is there a way to store both key and value in an item in a SWT Combo/List? If not, are there SWT components that look like a Combo and/or开发者_运维知识库 List that do?
Yes, there is. Use the setData( String key, Object value )
method.
Take a look at JFace, especially the viewers. The ComboViewer should be the right tool for the job.
Basically, the viewers are there for mapping between your domain objects and SWT components. There is even data binding functionality available which saves you a lot of boiler-plate code.
JFace Structured Viewers are the answer. Learn more about them here. They have a special combo implementation.
精彩评论