简体   繁体   English

如何限制ModifyListener仅用于用户交互

[英]How to limit ModifyListener for user interaction only

I have a textbox with attached ModifyListener. 我有一个带有ModifyListener的文本框。
In implemented modifyText(ModifyEvent e) I execute desired functionality. 在实现的ModifyText(ModifyEvent e)中,我执行所需的功能。

The problem with that, that this event is triggered on every text change. 问题在于,每次文本更改都会触发此事件。

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) 我希望它仅在用户更改代码时触发(我不能使用keylistener,因为当用户单击箭头按钮等时也会触发它,它也不会检测用户是否复制并粘贴文本)

您可以在调用setText(..)之前取消注册ModifyListener然后再重新注册。

而不是ModifyListener的textBox.addKeyListener(...)和textBox.addMouseListener(...)怎么样?

You can try using Focusout listener.... then you will get the value which user has entered only once. 您可以尝试使用Focusout侦听器...。然后,您将获得用户仅输入一次的值。

Text text;
text.addListener(SWT.FocusOut, new Listener() {
    @Override
    public void handleEvent(Event arg0) {

        //Your code here.....

    }
});

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

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