Adding items to a Combo
The following example uses a List to create a string array to set combo items:
String[] items = stringList.toArray(new String[0]);
Arrays.sort(items);
workflowCombo.setItems(items);
Selecting an item in a combo programatically
To select an item in a combo, you must first figure out the item index. The following example uses the Arrays class to find the index using the item array:
String wf = this.service.getWorkflowTemplate().getName(); //the string we want to select: wf
String[] workflowArray = this.workflowCombo.getItems(); //the item array
int index = Arrays.binarySearch(workflowArray, wf); // binarysearch returns index
this.workflowCombo.select(index); //select item with index
For the selection to work as expected, the Combo must be instantiated as READ_ONLY:
Combo typeCombo = new Combo(myComposite, SWT.READ_ONLY);
Detecting Selection Changes
Use a SelectionListener to detect changes:
workflowCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
updateSelectedWorkflow();
}
});