Auto scroll contents of SWT Browser [message #549760] |
Tue, 27 July 2010 20:44  |
Eclipse User |
|
|
|
Hello,
I am creating an application that requires an HTML report to be generated. I am using a SWT Browser to display the report and I need to auto scroll down as the report is filled.
I know that using getVerticalBar() will not work because the browser is nothing more than a embedded IE using OLE.
Is there any way to do this?
Thanks a lot,
Milton.
|
|
|
Re: Auto scroll contents of SWT Browser [message #549769 is a reply to message #549760] |
Tue, 27 July 2010 21:40   |
Eclipse User |
|
|
|
I was just working on a project that did this. Actually the Browser widget in RAP is just an iframe, but this should work equally well on SWT desktop version where it is using an embedded IE or Mozilla browser.
All I did is add a LocationListener to the Browser before calling setText() or setURL(). It executes a simple javascript call to scroll the browser to the bottom.
browser.addLocationListener(new LocationAdapter()
{
public void changed(LocationEvent event)
{
browser.execute("window.scrollTo(0, document.body.scrollHeight)");
}
});
|
|
|
Re: Auto scroll contents of SWT Browser [message #549874 is a reply to message #549769] |
Wed, 28 July 2010 10:05   |
Eclipse User |
|
|
|
Hi,
you should also be able to work with anchors in case you don't know
where to scroll the page exactly. Setting "foo.html#myanchor" as URL for
the Browser widget should do the trick.
Regards,
Ben
Cole Markham wrote:
> I was just working on a project that did this. Actually the Browser
> widget in RAP is just an iframe, but this should work equally well on
> SWT desktop version where it is using an embedded IE or Mozilla browser.
>
> All I did is add a LocationListener to the Browser before calling
> setText() or setURL(). It executes a simple javascript call to scroll
> the browser to the bottom.
>
>
> browser.addLocationListener(new LocationAdapter()
> {
> public void changed(LocationEvent event)
> {
> browser.execute("window.scrollTo(0,
> document.body.scrollHeight)");
> }
> });
>
>
--
Benjamin Muskalla | EclipseSource Karlsruhe
Need professional support for RAP and RCP?
Go to: http://eclipsesource.com/support
Twitter : @bmuskalla
Blog : http://eclipsesource.com/blogs/tag/rap/
|
|
|
Re: Auto scroll contents of SWT Browser [message #549927 is a reply to message #549760] |
Wed, 28 July 2010 13:44  |
Eclipse User |
|
|
|
Cole, thanks a lot for your reply that worked! I never payed attention to the execute method...
Benjamin thanks for your reply, but in my case I just need to scroll to the end of the HTML, I think I can't use anchors because the HTML I am displaying is not saved in a file as it is generated, I just use setText()
Thank you very much!
|
|
|
Powered by
FUDForum. Page generated in 0.03958 seconds