简体   繁体   中英

How to limit ModifyListener for user interaction only

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.

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然后再重新注册。

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

You can try using Focusout listener.... then you will get the value which user has entered only once.

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

        //Your code here.....

    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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