I have a Browser and I am adding content to it in a way similar to this:
browser.setText(browser.getText() + newText());
Then, when there is too more html than can fit inside the view, I want the browser to scroll down, so after each call to setText() I also do this (as suggested by answers to this question elsewhere on the web):
browser.execute("window.scrollTo(0, document.body.scrollHeight)");
However, this does not work! I’ve also tried using an anchor to scroll to, but that does not work either.
How can this be accomplished? Rather, where is the problem in my approach (which seems to have worked for others)?
Thanks
EDIT: Here’s my actual code:
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
final Browser browser = new Browser(shell, SWT.NONE);
browser.setBounds(10, 10, 430, 220);
Button btnNewButton = new Button(shell, SWT.NONE);
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
browser.setText(browser.getText() + "<p>weeee!!!</p>");
browser.execute("window.scrollTo(0, document.body.scrollHeight)");
}
});
btnNewButton.setBounds(10, 236, 430, 32);
btnNewButton.setText("New Button");
}
Well I’ve figured out a way to do this. It’s very similar to my above approach, only instead of
I used
Still not sure what the problem with my initial approach was though…