Используйте selectAll() в текстовой области GWT.

Моя страница GWT имеет TextArea, и я хотел бы, чтобы она была в фокусе и чтобы весь текст был выбран только при загрузке этой страницы. Я пробую код ниже, но он вообще не работает. Можешь мне помочь? Спасибо

final TextArea myText = new TextArea();
myText.setCharacterWidth(50);
myText.setVisibleLines(20);
myText.setText("Just try something");
RootPanel.get("textContainer").add(myText);
myText.setVisible(true);
myText.setFocus(true);
myText.selectAll();

person Community    schedule 01.08.2011    source источник


Ответы (1)


Документы TextBox.selectAll() говорят:

This will only work when the widget is attached to the document and not hidden.

Скорее всего, ваш TextBox еще не подключен к DOM, когда вы вызываете .selectAll().

Попробуйте использовать Scheduler:

final TextArea myText = new TextArea();
myText.setCharacterWidth(50);
myText.setVisibleLines(20);
myText.setText("Just try something");
RootPanel.get("textContainer").add(myText);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
        @Override
        public void execute() {
            // your commands here
            myText.setVisible(true);
            myText.setFocus(true);
            myText.selectAll();
        }
});
person Peter Knego    schedule 01.08.2011