3

私の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();
4

1 に答える 1

4

のドキュメントは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();
        }
});
于 2011-08-01T10:41:35.607 に答える