在GWT文本区域中使用selectAll()
我的GWT页面有一个文本区域,我希望它有焦点,并在加载此页面时选择所有文本。我尝试了下面的代码,但根本不起作用。你能帮助我吗?谢谢在GWT文本区域中使用selectAll(),gwt,textarea,selectall,Gwt,Textarea,Selectall,我的GWT页面有一个文本区域,我希望它有焦点,并在加载此页面时选择所有文本。我尝试了下面的代码,但根本不起作用。你能帮助我吗?谢谢 final TextArea myText = new TextArea(); myText.setCharacterWidth(50); myText.setVisibleLines(20); myText.setText("Just try something"); RootPanel.get("textContainer").add(myText); myTe
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();
TextBox.selectAll()的文档显示:
This will only work when the widget is attached to the document and not hidden.
调用.selectAll()
时,很可能您的文本框尚未连接到DOM
尝试使用计划程序
:
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();
}
});