Simulate click on menu item in SWT

677 Views Asked by At

I want to simulate a click on a menu item but found no method. I'm thinking of something like doClick() of JMenu.

At the moment my very stupid solution looks like this:

private void performClick(MenuItem source, Event event) {
  source.notifyListeners(SWT.Selection, event);
}

But maybe there's a better way to fire the event?

1

There are 1 best solutions below

0
On

A MenuItem in SWT can be controlled by the method

addSelectionListener(SelectionListener listener)

The SelectionListener provides the method

public void widgetSelected(SelectionEvent arg0) {}

where you can include the desired functionality.

For a documentation to the Class Menu Item see:

http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FMenuItem.html