I've been searching and searching and can't find a usable example of selecting all text within a GWT SuggestBox widget on focus. I understand you have to attach a focusListener to the widget, but then what? Can someone provide a working example of this?
Asked
Active
Viewed 1,963 times
1
-
Not sure what you need. Do you want the text highlighted on focus? – Jai May 23 '11 at 16:11
-
@Jai: Yep. That's right. – Chris Cashwell May 23 '11 at 16:19
2 Answers
4
Since every example I'd found online was using deprecated code (addFocusListener method), I ended up figuring this one out using the addFocusHandler method instead.
Here's how it was done:
mySuggestBox.getTextBox().addFocusHandler(new FocusHandler() {
@Override
public void onFocus(FocusEvent event) {
mySuggestBox.getTextBox().selectAll();
}
});

Chris Cashwell
- 22,308
- 13
- 63
- 94
-
-
use scheduler for selecting all on focus event: Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand () { public void execute () { mySuggestBox.getValueBox().selectAll(); } }); – Daniel Hári Jul 21 '15 at 10:56