This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes JTextPane and handling insertions of a large string. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextPane and handling insertions of a large string." Watch "JTextPane and handling insertions of a large string." New topic
Author

JTextPane and handling insertions of a large string.

steve labar
Ranch Hand

Joined: Sep 10, 2008
Posts: 55
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Consider Paul's rocket mass heater.
 
subject: JTextPane and handling insertions of a large string.