简体   繁体   中英

Simulate click on menu item in SWT

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM