更新时间:2023-01-13 15:04:44
将数据与组合框项目相关联的一种简单方法是使用JFace模型视图包装器 ComboViewer
.
One easy way to associate data with combo box items is to use the JFace model-view wrapper ComboViewer
.
然后,按以下顺序设置三件事:
Then, set three things, in this order:
ArrayContentProvider
是数组或集合的 .)例如:
myCombo.setContentProvider(new ArrayContentProvider());
myCombo.setInput( myModel );
myCombo.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) { ... }
});
完成此操作后,可以使用一些机制来获取选定的元素-或者可以获取包装好的 Combo
,要求其提供选定的索引,然后使用该索引来访问元素您的模型.
Once you've done that, there are mechanisms to get the selected element -- or you can get the wrapped Combo
, ask it for its selected index, and use that index to access an element of your model.