TextArea and "auto scroll" problem when adding new text

22 views
Skip to first unread message

eM

unread,
May 18, 2007, 7:45:57 AM5/18/07
to Google Web Toolkit
Hello, i have following problem:
i added TextArea, TextBox and button.
when i click on button, text from textBox is added to textArea.
everything works fine.. till my added text reached last line of
textArea. after that text is added but it is not visible (i have to
scroll it manually to see it) that is very annoying.

how i can make that scroll, to be done automatically? to focus on last
line added?
anyone had that problem?

cheers.
M.

Steiner Dominik, (QX59311)

unread,
May 18, 2007, 7:58:23 AM5/18/07
to Google-We...@googlegroups.com
Hi M.

Try something like this (the secret lies in area.setCursorPos(area.getText().length());)

public class Blubber20 implements EntryPoint{
public void onModuleLoad() {
VerticalPanel v = new VerticalPanel();
final TextArea area = new TextArea();
v.add(area);
final TextBox box = new TextBox();
Button btn = new Button();
v.add(box);
v.add(btn);
btn.addClickListener(new ClickListener(){
public void onClick(Widget sender) {
area.setText(area.getText()+box.getText());
box.setText("");
area.setCursorPos(area.getText().length());
}
});
RootPanel.get().add(v);
}

}
HTH

Dominik

-----Ursprüngliche Nachricht-----
Von: Google-We...@googlegroups.com [mailto:Google-We...@googlegroups.com] Im Auftrag von eM
Gesendet: Freitag, 18. Mai 2007 13:46
An: Google Web Toolkit
Betreff: TextArea and "auto scroll" problem when adding new text

eM

unread,
May 18, 2007, 10:21:32 AM5/18/07
to Google Web Toolkit
Thanks for replay Dominik, it works.. but only halfway:
it works in hosted mode and in IE, but in firefox doesnt. when new
message arive to textarea firefox add it and scroll up to first
messages.

any ideas?

M..

Max

unread,
Oct 24, 2011, 7:57:45 AM10/24/11
to google-we...@googlegroups.com, Google Web Toolkit
try this:


public static void scrollToBottom(Element e) {
e.setScrollTop(e.getScrollHeight() - e.getClientHeight());
}
Reply all
Reply to author
Forward
0 new messages