2011-08-01 13 views
3

私のGWTページにはTextAreaがあり、このページがロードされたときにフォーカスを持ち、すべてのテキストを選択したいと考えています。私は以下のコードを試してみるが、全く動作しない。手伝って頂けますか?おかげGWT TextAreaでselectAll()を使用

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

答えて

5

TextBox.selectAll()のドキュメントは言う:

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

おそらくあなたTextBoxあなたが.selectAll()を呼び出すとき、まだDOMに添付されていません。

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

!それは動作します、ありがとう! – Arturo

関連する問題