View Full Version : TextArea auto scroll
hordur
20 Jan 2009, 4:43 PM
Hello,
I'm updating a TextArea with a timer and would like to have it scroll down to the bottom, so the newest messages (at the bottom) are visible.
With javascript this could be done using a div:
objDiv.scrollTop = objDiv.scrollHeight;
...but I'm not sure how to do this in gwt/gxt. Does anyone know how to do this stuff?
kolli
21 Jan 2009, 8:45 AM
Have you tried it??
Because i think the scroll bar will always be in the bottom of the textarea unless moved. so It is always the newest messages that is visible.
hordur
21 Jan 2009, 9:03 AM
Yes, I tried it, but the scrollbar stays at the top, not the bottom.
kolli
21 Jan 2009, 9:38 AM
can you post some sample code so that we can have a look?
hordur
21 Jan 2009, 12:27 PM
Here's a small example.
import java.util.Date;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.RootPanel;
public class TextAreaTest implements EntryPoint {
public void onModuleLoad() {
LayoutContainer lc = new LayoutContainer();
Viewport v = new Viewport();
v.setLayout(new FitLayout());
v.add(lc);
RootPanel.get().add(v);
lc.setLayout(new FitLayout());
final TextArea txt = new TextArea();
lc.add(txt);
txt.setReadOnly(true);
txt.setValue(" ");
Timer timer = new Timer() {
public void run() {
txt.setValue(txt.getValue()+"\n"+(new Date()));
}
};
timer.scheduleRepeating(1000);
}
}
hordur
23 Jan 2009, 4:48 PM
Found out how to do this. Didn't realize that I had access to the JS obj:
txt.getElement().setScrollTop(txt.getElement().getScrollHeight());
kolli
26 Jan 2009, 5:33 AM
wow!!, good thanks i didnot know that :)
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.