SWT 事件传播
我正在尝试检测包含许多其他组合的组合控件上的单击事件。我尝试过:
topComposite.addMouseListener(new MouseListener() {
...
@Override
public void mouseUp(MouseEvent arg0) {
logger.info("HERE");
});
});
但该事件从未触发。我假设当鼠标事件发生在孩子身上时,它会沿着链向上传播,但这种情况并没有发生。我该怎么做?
I'm trying to detect click events on a Composite control that contains a number of other composites. I tried:
topComposite.addMouseListener(new MouseListener() {
...
@Override
public void mouseUp(MouseEvent arg0) {
logger.info("HERE");
});
});
But the event never fires. I assumed that when a mouse event occurred on a child it would propagate up the chain but that doesn't happen. How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 SWT 中,一般规则是事件不传播。主要的例外是遍历事件的传播——这很难描述。
问题的简单答案是,您必须将侦听器添加到您的
Composite
的所有子级中 - 递归地!例如,像这样
点击的小部件可以在
e.widget
中找到,如上所示。一个重要的问题是,如果您稍后添加更多控件
,请记住再次执行此操作。In SWT, the general rule is that events do not propagate. The main exception to this, is the propagation of traverse events - which is pretty complicated to describe.
The easy answer to your problem is that you must add the listener to all the children of you
Composite
- recursively!E.g. like this
The clicked-upon widget is found in
e.widget
as seen above. An important issue is to remember to do this again if you add moreControls
later.