Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在GWT文本区域中使用selectAll()_Gwt_Textarea_Selectall - Fatal编程技术网

在GWT文本区域中使用selectAll()

在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

我的GWT页面有一个文本区域,我希望它有焦点,并在加载此页面时选择所有文本。我尝试了下面的代码,但根本不起作用。你能帮助我吗?谢谢

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();
        }
});