• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to put an HTML file in a JEditorPane ?

 
Onur GAGO
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please explain me how to put an HTML file in a JEditorPane?
Here is what I do:
1- create the URL String of my file (eg. "file://sample.html")
2- use this string with JEditorPane's setPage() method
(eg.jEdtitorPane1.setPage("file://sample.html")
Note: I set the EditorPane's context type to : "text/html"
And here is the exception:
*** java.util.StackException (stack is full)***
and this exceptions occurs after setPage() method. It is related wiht the HTMLEditor kit or something...
What's this HTMLEditor? How can I use it? How can I solve my problem.
Thanks a lot.
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this sample...takes some time to load..
JEditorPane edit = new JEditorPane();
edit.setEditable(false);
edit.setPage(new URL("http://www.yahoo.com"));
JScrollPane editorScrollPane = new JScrollPane(edit);
editorScrollPane.setPreferredSize(new Dimension(250, 145));
JFrame frame2 = new JFrame();
frame2.getContentPane().add(editorScrollPane);
frame2.setSize(400,400);
frame2.setVisible(true);
 
Onur GAGO
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. it works with the URL http://www.yahoo.com
However i want to put a local html file in the jEditorPane.
and use "file://localhost/c:/..../sample.html".
after calling the method
jEditorPane1.setPage(new URL("file://localhost/c:/..../sample.html"))
an exception occurs:
------------------------------------
java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:82)
at javax.swing.text.DefaultStyledDocument$ElementBuffer.insertElement(DefaultStyledDocument.java:1623)

at javax.swing.text.DefaultStyledDocument$ElementBuffer.create (DefaultStyledDocument.java:1283)
at javax.swing.text.DefaultStyledDocument.create(DefaultStyledDocument.java:131)
at javax.swing.text.html.HTMLDocument.create(HTMLDocument.java:244)
at javax.swing.text.html.HTMLDocument$HTMLReader.flushBuffer(HTMLDocument.java:3012)
at javax.swing.text.html.HTMLDocument$HTMLReader.flush(HTMLDocument.java:1921)
at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:240)
at javax.swing.JEditorPane.read(JEditorPane.java:421)
at javax.swing.JEditorPane$PageLoader.run(JEditorPane.java:468)
-------------------------------
where's the problem? How should I create the URL with a local file?
 
Michael Szul
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URL will probably need to be "file:///c:/" or "http://localhost/whatever_the_directory/whatever_the_file.html" (if you're running a web server).
However, I recommend using relative path names to avoid platform dependence or maybe even class loaders if you're stuffing it all into jar files.
 
mohamed zafer
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There,
I am using JEditorPane to display a HTML form. Can I retrieve the data (field values)entered in the HTML form from my Java application. If so how..?. Also it would be of help to me, if I know whether the events like submit or reset can be trapped, like how links are trapped using HyperlinkListener.
Thanks in advance
Mohamed Zafer
 
Onur GAGO
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved my problem. Thanx everybody.
This stack exceptions occurs because of the size of my HTML file. I read the HTML file from my DB as a ByteStream and then create the HTML file from this ByteStream. Afterwards I use the file with JEditorPane. However, while creating the file from this ByteStream, I have assumed that all files would be 8K. But the content of the byteStream was smaller than 8K and this caused the problem.
By the way I'm sorry, I don't know how to listen HTML actions such as submit.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!