Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to use Browser to render html files in jar file?
How to use Browser to render html files in jar file? [message #433338] Wed, 07 April 2004 17:02 Go to next message
Eclipse UserFriend
Originally posted by: doublexia.hotmail.com

I was trying to display html files in jar file. I used these in my
application:
Browser browser = new Browser(container, SWT.NONE);

Class baseClass = this.getClass();

URL url = baseClass.getResource(anHtmlFile);

System.out.println("URL =" + url);

browser.setUrl(url.toString());



This didn't work. The print statement shows something like this:

jar:file:jar_file_name!class_path/htmlfile_location

Do I have to use browser.setText()?



Thanks.
Re: How to use Browser to render html files in jar file? [message #433434 is a reply to message #433338] Thu, 08 April 2004 11:44 Go to previous messageGo to next message
Michal Tkacz is currently offline Michal TkaczFriend
Messages: 105
Registered: July 2009
Senior Member
Użytkownik Double Xia napisał:
> I was trying to display html files in jar file. I used these in my
> application:
> Browser browser = new Browser(container, SWT.NONE);
>
> Class baseClass = this.getClass();
>
> URL url = baseClass.getResource(anHtmlFile);
>
> System.out.println("URL =" + url);
>
> browser.setUrl(url.toString());
>
>
>
> This didn't work. The print statement shows something like this:
>
> jar:file:jar_file_name!class_path/htmlfile_location
>
> Do I have to use browser.setText()?
>
>
>
> Thanks.
>
>

I had the same problem (see my post "How to open a file from jar file in
Browser widget on Windows" posted 19.03.2004). Unfortunately no one was
able to help me :(

If you're using Linux, the browser widget is Mozilla, which supports
urls of the form returned by getResource(). However if you're using
Windows, the browser is Internet Explorer. In this case you may use
getResourceAsStream() method instead, read the contents of the file to
the memory and then set it in the browser using setText() method.

Hope this helps

Michal
Re: How to use Browser to render html files in jar file? [message #451717 is a reply to message #433434] Mon, 07 March 2005 13:13 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 12
Registered: July 2009
Junior Member
Not sure if this is still relevant to anyone anymore, but I found this seems
to work for loading within Jar's. Not sure how efficient it is though...
URL url = new URL(url);
InputStreamReader reader = new InputStreamReader(url.openStream());
BufferedReader br = new BufferedReader(reader);
String str;
StringBuffer sb = new StringBuffer();
while((str = br.readLine())!=null){
sb.append(str);
}
browser.setText(sb.toString());

"Michal Tkacz" <mehow.remove@neurosoft.net> wrote in message
news:c53dk6$vop$1@eclipse.org...
> U
Re: How to use Browser to render html files in jar file? [message #451727 is a reply to message #451717] Mon, 07 March 2005 15:59 Go to previous message
No real name is currently offline No real nameFriend
Messages: 12
Registered: July 2009
Junior Member
Oh...its not as trivial as that. Should the SWT implementation handle this,
or is it the responsibility of the programmer? Why does the setUrl method
take a type String argument rather than a java.net.URL one?


"jayshan" <jr200@doc.ic.ac.uk> wrote in message
news:d0hoi8$hc$1@www.eclipse.org...
> Not sure if this is still relevant to anyone anymore, but I found this
seems
> to work for loading within Jar's. Not sure how efficient it is though...
> URL url = new URL(url);
> InputStreamReader reader = new InputStreamReader(url.openStream());
> BufferedReader br = new BufferedReader(reader);
> String str;
> StringBuffer sb = new StringBuffer();
> while((str = br.readLine())!=null){
> sb.append(str);
> }
> browser.setText(sb.toString());
>
> "Michal Tkacz" <mehow.remove@neurosoft.net> wrote in message
> news:c53dk6$vop$1@eclipse.org...
> > U
Previous Topic:Screen size on PocketPC
Next Topic:WebBrowser Control- XP Style
Goto Forum:
  


Current Time: Sat Sep 26 09:12:55 GMT 2020

Powered by FUDForum. Page generated in 0.02499 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top