How to limit ModifyListener for user interaction only

穿精又带淫゛_ 提交于 2019-12-11 07:37:41

问题


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)


回答1:


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




回答2:


How about textBox.addKeyListener(...) and textBox.addMouseListener(...) instead of ModifyListener?




回答3:


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.....

    }
});


来源:https://stackoverflow.com/questions/9385298/how-to-limit-modifylistener-for-user-interaction-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!