如何限制ModifyListener仅用于用户交互 [英] How to limit ModifyListener for user interaction only

查看:55
本文介绍了如何限制ModifyListener仅用于用户交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个附加了ModifyListener的文本框.
在实现的ModifyText(ModifyEvent e)中,我执行所需的功能.

I have a textbox with attached ModifyListener.
In implemented modifyText(ModifyEvent e) I execute desired functionality.

问题在于,每次文本更改都会触发此事件.

The problem with that, that this event is triggered on every text change.

如果通过编程方式更改文本(通过代码设置文本),我不希望它触发. 我希望它仅在用户更改代码时触发(我不能使用keylistener,因为当用户单击箭头按钮等时也会触发它,它也不会检测用户是否复制并粘贴文本)

I don't want it to trigger if text was altered programmaticly (by setting text via code). I want it to trigger only when user changes the code (I can't use keylistener because it will be triggered also when user click on arrow buttons and etc, it also won't detect if user copy&paste text)

推荐答案

您可以在调用setText(..)之前先注销ModifyListener,然后再重新注册.

You could unregister your ModifyListener before calling setText(..) and reregister it afterwards.

这篇关于如何限制ModifyListener仅用于用户交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆