[英]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. 我在想类似JMenu的doClick()的东西。
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 可以通过以下方法控制SWT中的MenuItem
addSelectionListener(SelectionListener listener) addSelectionListener(SelectionListener侦听器)
The SelectionListener provides the method SelectionListener提供方法
public void widgetSelected(SelectionEvent arg0) {} 公共无效的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 http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FMenuItem.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.