• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextPane and handling insertions of a large string.

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having a difficult time trying to optimize the adding of a large file to a JTextPane. I have searched everywhere on the internet and cannot seem to find anything that looks feasible. One site mentions removing the JTextPane's document while insertions are being done to avoid any unnecessary updates. I tried this but it did not seem to help much.

What I'm thinking of doing is creating the zone model where i load a chunk of the data and listen for the user to reach the end of the scrollbar. At that point I add another chunk to the pane.

I have that functionality working fine. However, I would like to make the insertion of text much more efficient. Anyone have any tips how to speed things up?

- I grab text from file and put into a string > mb - this is fine

- I then call pane.settext(string) -> this is where things really hang.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you can import the file in smaller chunks, using a SwingWorker:
This example reads the file line by line. Perhaps you can read pieces of X characters, having X some kind of constant that's large but not too large.

By using a SwingWorker like this you will not have one large update to the document but several smaller ones. The effect should be a somewhat more responsive user interface.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic