This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes HTMLEditorKit & Performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "HTMLEditorKit & Performance" Watch "HTMLEditorKit & Performance" New topic

HTMLEditorKit & Performance

emmanuel soyeux

Joined: Aug 09, 2001
Posts: 4
I develop a java reporting tool which generates outputs in several formats(HTML,TXT,RTF...)
This component is accessible either a Client/Server Application written with Swing library , either a web-application.
When we use the swing application, a JEditorPane is used to retrieve the reports, associated with a correspondant EditorKit.
Even if the report is small (20 Ko), it takes time to display it in HTML..... and if you relaunch it many times, the application hangs up (memory leak ?)
With TXT, it is good and with the web-application too.
I suppose (and i'm sure with JBuilder !) that the problem is due to the read method called with,doc,pos)....
Thanks for your help.
clio katz
Ranch Hand

Joined: Apr 30, 2004
Posts: 101
Originally posted by emmanuel soyeux:
it takes time to display it in HTML..... and if you relaunch it many times, the application hangs up (memory leak ?)

hmmm. relaunch it many times? not in a hurry i hope:-)

just fishin' in the dark but have you tried apache's httpclient?

they have a nice sample that will write output to a JEditorPane, so you could do a litmus test:

i mention this because i've seen prev complaints about hangs because java doesn't support setting http connection timeout. this may or may not be related to your issue, but it might be interesting to see if this helps to isolate the problem (in the editor kit or otherwise)

good luck - let us know how it comes out!
emmanuel soyeux

Joined: Aug 09, 2001
Posts: 4
The previous code from Apache is quite similar to my own one.
To be short,the problem occurs in these lines
JeditorPane editorPane; // already defined
InputStreamReader reader; // already defined
HTMLDocument doc = new HTMLDocument();, doc); => problem !!!

This takes a long time and the VM increases strongly!!
Same behaviour with using HTMLEditorKit, ......

What's wrong ?
clio katz
Ranch Hand

Joined: Apr 30, 2004
Posts: 101
i gave this a quick try and ... it wasn't so quick. however, performance was not horrible - especially for smaller or less complex documents.

just some ideas from a 10k ft view:

possible places to look(?) -

(1) Format of the HTML report(s) you're reading

JEditorpane - from what i can see - has about 15 html handling bugs being fixed in 1.5, including an important-looking META tag support bug.

API gives current HTML support at 3.2 (if in doubt, report
compliance could be verified w tool like jtidy also see last item below)

(2) issues related to _read (vs. using constructor or _setPage)

(a) *non* asynch vs asynch performance; (b) existence of
relative path refs (determination of basedir), (c) content type, etc.

(3) content itself
can be set/checked before/after instantiation.
any possibility of charset issues? is doc editable?

finally, there's a jeditorpane-based simple browser (platespiller ) out there that you could use as a baseline - to see if these reports display ok using that browser, and to check the rendering integrity and performance deltas

hth - good luck!
emmanuel soyeux

Joined: Aug 09, 2001
Posts: 4
For all projects regarding a java browser for HTML Document, they always use JeditorPane with read or setPage method......

My own code concerning the HTML viewver of the application seems to the following lines :

JEditorPane editorPane= new JEditorPane();
editorPane.setContentType("text/html; charset=ISO-8859-1");
HTMLEditorKit htmlKit = new HTMLEditorKit();
Document doc = htmlKit.createDefaultDocument();
//To have the focus on this dialogBox...
JWindow wnd = new JWindow();

//Loading data...
try {,doc);

} catch (Exception e) {
System.out.println(e); // => The second run fails !

JScrollPane editorScrollPane = new JScrollPane(editorPane);
editorScrollPane.setPreferredSize(new Dimension(500, 500));
editorScrollPane.setMinimumSize(new Dimension(100, 100));

setLayout(new GridBagLayout()); //The general panel which embedds the editorPane

The problem is awalys in the read method......
I have the feeling that some static objects associated to the editorkit, htmldocument...... are not properly cleaned
but when i close the window, all the objects are reset to null (and as they are locally, java can remove them from memory thanks to garbage collector..... but we can help this process.....)
I agree. Here's the link:
subject: HTMLEditorKit & Performance
It's not a secret anymore!