我创建了一个ComboViewer
final ComboViewer comboViewer = new ComboViewer(shlFreeViews, SWT.NONE);
final Combo combo = comboViewer.getCombo();
combo.setVisibleItemCount(4);
combo.setFont(SWTResourceManager.getFont("Segoe UI", 13, SWT.NORMAL));
combo.setItems(new String[] {"5", "10", "15", "20"});
combo.setBounds(356, 172, 126, 25);
combo.setText("5");
问题是,当我打开程序时,我必须选择一些我的comboviewer,然后我必须使用这个数字做一个简单的添加。获取所选编号的comboviewer的代码是什么?
答案 0 :(得分:6)
您可以向ISelectionChangedListener
添加ComboViewer
,以便在选择更改时收到通知,或者您可以手动获取。程序是一样的:
StructuredSelection sel = (StructuredSelection) viewer.getSelection();
YourDataType element = (YourDataType) sel.getFirstElement();