0

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!?

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
Johanna
  • 27,036
  • 42
  • 89
  • 117
  • You're going to have to provide a lot more detail. – Sean Bright Aug 06 '09 at 14:57
  • do you want the source of the html in the text area ? – n00ki3 Aug 06 '09 at 14:58
  • I want to show the content of that html file in the text area not the source of that file – Johanna Aug 06 '09 at 15:01
  • for example I have a html file in my computer and I want to show its content in the text area.How can I find the source of that file? – Johanna Aug 06 '09 at 15:03
  • You get the file into a string... and you print it out. I don't know anything about JEditorPane, so I won't make this an answer. You should also specify whether or not the file will need any server-side processing done to it first, as that will affect whether or not you can just dump the file contents into your page. – Xiong Chiamiov Aug 06 '09 at 17:38

3 Answers3

1

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.

Community
  • 1
  • 1
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
0

Format the HTML with a <pre> tag

Chris Ballance
  • 33,810
  • 26
  • 104
  • 151
0

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
  • 4,327
  • 5
  • 35
  • 52