Display problem in JEditorPane

M

Michael Jung

I have the following problems, someone may already have experienced or knows
how to solve.

I have a JEditorPane that contains an HTMLDocument, which contains some
referenced images, i.e. <img>-tags. Now, I'd like to display this in Graphics
context that is not the GUI (where everything works fine).

The problem is that immediately after I load the document, the images seem not
to be available for drawing. This fits with the fact that the GUI elements on
screen get redrawn as images get loaded successively. However, I cannot find
a proper event to listen to, that tells me that the JEditorPane is finished
drawing. I also can't find anything at the HTMLDocument, but I presume that
would be the wrong object anyway.

Additionally there may be a problem that simple drawing of the JEditorPane
without actually "showing" it, might not convince that component to draw the
images at all. I have experimented a little with the
SwingUtilities.paintComponent to circumvent this but it apparently didn't
help.

Thanks,
Michael
 
H

hiwa

I have the following problems, someone may already have experienced or knows
how to solve.

I have a JEditorPane that contains an HTMLDocument, which contains some
referenced images, i.e. <img>-tags. Now, I'd like to display this in Graphics
context that is not the GUI (where everything works fine).

The problem is that immediately after I load the document, the images seem not
to be available for drawing. This fits with the fact that the GUI elements on
screen get redrawn as images get loaded successively. However, I cannot find
a proper event to listen to, that tells me that the JEditorPane is finished
drawing. I also can't find anything at the HTMLDocument, but I presume that
would be the wrong object anyway.

Additionally there may be a problem that simple drawing of the JEditorPane
without actually "showing" it, might not convince that component to draw the
images at all. I have experimented a little with the
SwingUtilities.paintComponent to circumvent this but it apparently didn't
help.

Thanks,
Michael

public class HTMLEditorKit2 extends HTMLEditorKit{
public Document createDefaultDocument(){
HTMLDocument doc = (HTMLDocument)(super.createDefaultDocument());
doc.setAsynchronousLoadPriority(-1); //do synchronous load
return doc;
}
}
 
M

Michael Jung

public class HTMLEditorKit2 extends HTMLEditorKit{
public Document createDefaultDocument(){
HTMLDocument doc = (HTMLDocument)(super.createDefaultDocument());
doc.setAsynchronousLoadPriority(-1); //do synchronous load
return doc;
}
}
------------------------------------------
JEditorPane.registerEditorKitForContentType("text/html",
"HTMLEditorKit2");
JEditorPane jep = new JEditorPane();
jep.setEditorKitForContentType("text/html", new HTMLEditorKit2());

Doesn't help. It speeds up the drawing, but it's not fast enough (apparently).
I'm not sure this should really do the trick, because the GUI loading also
still shows some lag.

That also makes sense, since displaying an HTML document depends on the
size/layout of the JEditorPane itself, which can vary during time, while the
loading of the document happens only once.

[Technically, I'm not using any difficult layout in the document, but the
possibility should show that the HTML layout is a seperate process from the
document loading, which is now synchronous.]

I hope there is something about the JEditorPane that tells me when the doc is
fully layed out, since the GUI Layout manager somehow knows (I hope).

Michael
 
R

Roedy Green

I hope there is something about the JEditorPane that tells me when the doc is
fully layed out, since the GUI Layout manager somehow knows (I hope).

The HTML rendering inside Java is pretty Mickey Mouse. Perhaps you
needa more powerful rendering engine. see
http://mindprod.com/jgloss/htmlrendering.html

If you have a masochistic streak, you might consider rendering the
images yourself on a separate layer and somehow jostling them around
to render over top of the mangled images produced by Java.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top