Code fire event

I am writing an RCP application in eclipse that contains a combobox, and when any of its elements are selected, a selection event is fired and some random code is fired. The listener looks something like this:

randomComboBox.addSelectionListener(new SelectionListener(){ @Override public void widgetSelected(SelectionEvent e) { // random code } @Override public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }); 

My question is: is it possible to fire an event from code? For example, if I add:

 randomComboBox.select(0); 

no event is fired. In this case, do I need to write my own listener?

+4
source share
1 answer

The select method in the combo box dispatches an event of type SWT.Modify when it changes the selection, so you can use ModifyListener instead of SelectionListener .

Actually, ModifyListener listens for changes in the text box of the combo box, which means that it responds to a change in text caused by the selection. It also means that it will be launched if this text is changed in other ways (for example, user entries in the combo text field).

Keeping this behavior is probably a variant of ModifyListener .

+4
source

Source: https://habr.com/ru/post/1435594/


All Articles