My application shows RSS entries in a JEditorPane. It works not that bad, but I've encountered a serious issue lately while displaying a gif. Here's a small test case :
public class JEditorPaneTest
{
public static void main(String[] args)
{
JFrame dialog = new JFrame("JEditorPane test");
dialog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = dialog.getContentPane();
c.setLayout(new BorderLayout());
JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new HTMLEditorKit());
editorPane.setText("<html><body><img src=\"http://feeds.feedburner.com/~ff/MacRumors-All?d=yIl2AUoC8zA\"></body></html>");
c.add(new JScrollPane(editorPane), BorderLayout.CENTER);
dialog.pack();
dialog.setVisible(true);
}
}
The unanimated gif is flickering and the CPU usage is up to 300% (quad-core computer) on Mac OS X or 50% on Windows 7. This issue is even more severe since after disposing the editor pane, the CPU usage is still that high.
Looking at some profiling, it looks like 50% of the cpu usage time is in the Event dispatcher thread and the other 50% is in sun.awt.image.ImageFetcher.run().
Another interesting fact is that it happens also when embedding html in a JLabel.
(EDIT : 9 march 2012) Another interesting fact is that if the file is downloaded locally first (and accessed by file://...) or even, being a resource do not fix anything. But if the image is shown in ImageIcon in a JLabel, there is no flickering and high CPU usage. Somehow, I really need to use a HTML document in a JEditorPane to render some basic HTML formatting.
I am looking for a general solution to avoid censoring images from feedburner.com and, these gifs from feedburner.com are the only one I found yet, but I would like prevent having the bug with all other images that could behave the same way.
Thanks a lot.