5

I'm trying to load an HTML file that is large approximately 2MB (1927KB for the sake of precision) into a JEditorPane, and it takes about 65 seconds, it seems to be a bug of the JTextPane/JEditorPane, i have read also several articles on the web like this one, but i couldn't find a solution ...

Here's the code that i use :

final String htmlContent = //Load a 2MB String
previewPane.setContentType("text/html; charset=UTF-8");     
previewPane.setText(htmlContent);

The setText method takes about 65seconds to get completely executed as you can see in my application log :

Set the html content(1927KB) of the Preview pane, loading time=68230ms
Set the html content(1927KB) of the Preview pane, loading time=62693ms
Set the html content(1927KB) of the Preview pane, loading time=66583ms

Is there a way to solve this problem ?

About 65 seconds to load 2MB of Text is a terrible performance on an Intel Core 2 Duo 2.93GHz with 8GB of DDR 3 RAM ...

aleroot
  • 71,077
  • 30
  • 176
  • 213
  • `//Load a 2MB String (read over next 3 life times)` What use-case justifies loading nearly 2MB of HTML? – Andrew Thompson Jan 28 '12 at 15:32
  • It is a content of a report that i want to show in a PreviewPane, 2MB file is not so big ... – aleroot Jan 28 '12 at 15:35
  • That is a large amount of HTML. Remember that it has to be processed. So even if 2MB does not seem a lot, after processing and creating all the GUI components the memory footprint can be quite huge. Try opening your 2MB HTML with a browser or another HTML editor and compare the performance... – Alex Calugarescu Jan 28 '12 at 15:42
  • @aleroot : Then write your code in c++ or try this :http://wiki.eclipse.org/JFace . It uses the native GUI components so it works way better than swing. – Alex Calugarescu Jan 28 '12 at 15:44
  • @Alex Calugarescu : Are you serious ? If i open the file in Safari or Chrome it get nearly 2 seconds to get completely loaded ... – aleroot Jan 28 '12 at 15:46
  • You could try one of the alternative components mentioned in this thread: http://stackoverflow.com/questions/145863/best-java-swing-browser-component –  Jan 29 '12 at 08:11

1 Answers1

3

May be some of the tricks help http://java-sl.com/JEditorPanePerformance.html

StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • I have already tried with these tricks but they improve only the rendering phase but not the loading phase (seText) ... In my Question i had specified that i have already tried that tricks ... – aleroot Jan 29 '12 at 08:10
  • What happens if you load Document only? how much time do you need to load pure newly created Document? How much time do you need to render the Document by calling textPane.setDocument(docInstance)? – StanislavL Jan 29 '12 at 12:24
  • Set the html content(1927KB) in the Preview pane, loading time=109051ms It is worse . – aleroot Jan 29 '12 at 14:21