tags:

views:

97

answers:

3

How can I open an HTML page and show it in a text area? (If I choose the HTML file with the JFileChooser, how can I open that page and show it in the text area?)

URL url = new URL(String s);
JEditorPane pane = JEditorPane(url);

But how can I find the link of the HTML file for inserting as s, here!?

A: 

Format the HTML with a <pre> tag

Chris Ballance
+1  A: 

A TextArea is for displaying/editing text, not for showing formatted HTML.

JEditorPane supports HTML markup, but only a rather limited subset.

For full HTML support, you're going to need third-party components. Look at the answers to this question for links.

Michael Borgwardt
Woud you mind saying an example with JEditorPane??
Johanna
A: 

I guess you can use any properly formatted URL a browser would use e.g.

http://stackoverflow.com/questions/1239454/how-can-i-open-an-html-page-and-show-it-in-a-text-area

But then again Java is very keen on security and you might not be allowed to use certain URLs in your environment.

And like Michael Borgwardt said - the JEditorPane's support of HTML is very limited and some tags (i think <div> is one of them) as well as JavaScript are not supported.

For implementation of a simple browser have a look at this
JEditorPane Tutorial

Stroboskop