阅读gwt中的ONPaste Event上的文字

时间:2016-02-16 04:47:14

标签: java gwt onpaste

我在ONPASTE事件上遇到问题。假设我有5个文本框,我正在使用sinkEvent,那么我将如何获得将被粘贴到任何文本框中的文本

public abc() {
    super();
    TextBox t1 = new TextBox();
    TextBox t2 = new TextBox();
    TextBox t3 = new TextBox();
    TextBox t4 = new TextBox();
    TextBox t5 = new TextBox();

    sinkEvents( Event.ONPASTE );
}

@Override
public void onBrowserEvent(Event event) {
    super.onBrowserEvent( event );

    switch (DOM.eventGetType(event)) {
        case Event.ONPASTE:
            //Now here i want to read get the text which is going to be 
            //pasted in the any of the textbox
    }
}

1 个答案:

答案 0 :(得分:1)

你必须在文本框中捕获事件。您可以扩展文本框以在onpaste事件上触发事件,或者像这样快速和脏地执行:

public abc() {
    super();
    TextBox t1 = new TextBox(){

        @Override
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            checkForPastEventAndDoSomething(event);
        }
    };
    //...
}

private void checkForPastEventAndDoSomething(Event event) {
    switch (event.getTypeInt()) {
                case Event.ONPASTE:
                //Now here i want to read get the text which is going to be 
                //pasted in the any of the textbox
                break;
}