How to limit ModifyListener for user interaction o

2019-07-25 16:09发布

问题:

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

    }
});


标签: java swt jface