• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Efficent way to display HTML?

 
Greenhorn
Posts: 11
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I currently have a Java application that fetches data through JDBC. My current method is to have a StringBuffer append the data it fetches and then do setText(Stringbuffer.toString()) in Jeditorpane.
r = sqlquery.executeQuery(query);
while(r.next())
{
content.append("("+r.getString(1)+":"+r.getString(2)+")"+r.getString(3));
}
editorPane.setText(content.toString());
While this works, sometimes the size/amount of the html text it retrieves can range up to 200K. All the appending with string buffer can put a serious lag on performance.
Does anyone have any recommendations for possibly other Swing components that can display html or perhaps a more efficent way to display html with JEditor. I know Jeditor has a read(inputstream) which would be ideal and probably would work better, but my data source isnt an input stream.
Any one have any clever solutions to this.. or should i just give in and break down my editor into multiple "pages"
Any tips appreciated. Thanks
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Break the line -



into -



You might get some performance increase there... you're still doing a normal String concatenate inside the StringBuffer append. The new code will use the StringBuffer append to it's highest potential.

JEditorPane does take notoriusly long to display large chunks of HTML, so if you regularly get 200K worth of results, you may way to split up the results into pages.

Just asking, but is the data already saved as HTML in the database, or are you using the StringBuffer method above to build the HTML? Seems like there might be better ways of dealing with the data than building a webpage to display on a JEditorPane if this isn't the case...
 
Chad Patrick
Greenhorn
Posts: 11
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Nate
I appreciate the reply. In an attempt to benchmark your response with the code I already had, It insprired me to do alot more indepth looking into the recklessness of my code. It turns out that it was taking on average about 8 seconds to retrieve and perform all the appends, plus another 8-9 seconds for the jeditorpane to display. I believe that the length of one string buffer came out to be 200,000 So Im defiently gonna split the results into different pages. Maybe doing that will also cure that nasty memory leak I seemed to provoked in Jeditorpane.
Also on JeditorPane, Ive seen some posts on google referring to a memory leak with it which I think I have fallen victim to.
public class wide nonstatic variable Jeditorpane contentpane
local method called on button press
{
StringBuffer x = new StringBuffer();
Do a few x.appeands
contentpane.settext(x.toString());
}
After performing the above pseudocode a few times, It seems that Java never releases the memory. I can watch on Task Manager where memory usage just seems to keep growing and growing each button press. The code above is located in an ActionListener response to button press. Are there any certain precautions you should take when doing repetitive settext() calls on Jeditorpanes, or was jeditorpane never built to handle this type of repetitive display.
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic