简体   繁体   English

检测更改事件的来源

[英]Detecting where a change event came from

I have a bunch of JTextComponents that fire update events to a common model. 我有一堆JTextComponents可以将更新事件激发到一个通用模型。 The model then fires out change events to the other components so they can all be in synch. 然后,模型将更改事件激活到其他组件,以便它们可以同步。 How can I detect which one fired the event initially so as not to fire the event back? 我怎样才能检测出哪一个最初触发了事件,以免发回事件? I ask this as I'm currently getting an expection due to attemtping to update the component that fired the event. 我问这个,因为我正在尝试更新触发事件的组件。

There should be a getSource method on the event object. 事件对象上应该有一个getSource方法。 Use that to obtain a reference to the component that originally fired the event. 使用它来获取对最初触发事件的组件的引用。 You can then skip that component when distributing the event. 然后,您可以在分发事件时跳过该组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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