How do i find out which GWT element has focus?

后端 未结 4 587
深忆病人
深忆病人 2021-01-13 07:58

I would like to find out, in GWT, which element currently has focus. Basically i was working on virtual keyboard in our application. All keys are working fine except tab key

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-13 08:41

    Short template:

    public class IntBox extends com.google.gwt.user.client.ui.IntegerBox {
    
    private boolean focused=false;
    
    public IntBox(){
    
            addFocusHandler(new FocusHandler() {
    
                @Override
                public void onFocus(FocusEvent event) {
                    focused=true;
                }
            });
    
            addBlurHandler(new BlurHandler() {
    
                @Override
                public void onBlur(BlurEvent event) {
                    focused=false;
                }
            });
    
        }
    
        public boolean isFocused() {
            return focused;
        }
    
    }
    

提交回复
热议问题