Why is there no isFocused() in GWT?

前端 未结 2 1766
死守一世寂寞
死守一世寂寞 2020-12-19 03:19

In a programming scenario, I needed to check if my GWT textbox was focused or not. I ended up adding a boolean and a pair of Focus & BlurHandler to manually keep the foc

2条回答
  •  天命终不由人
    2020-12-19 03:40

    To find which widget has focus, I don't know whether you have solution already. As a novice to GWT , I propose my solution to share:

    1. Declare private field in the object, like 'focusedWidget' step 1

    2. Create focus handler for the widget, here's class TextBox. In OnFocus block, just assign the widget to 'focusedWidget'. You can add this kind of event to every widget that can be focused. ![step 2][2]

    3. That's all. Every widget you tied the focus event will set itself to 'focusedWidget' everytime it is focused. We can then use 'focusedWidget' to determind which current widget is focused. ![step 3][3]

    I test it in JUnit, it works! see image of snippet here Hope that help.

提交回复
热议问题