views:

621

answers:

3

Hello,

We need to load and display large files (rich text) using swing, about 50mb. The problem is that the performance to render the files is incredibly poor. We tried both JTextPane and JEditorPane with no luck.

Does someone have experience with this and could give me some advise ?

thanks,

+6  A: 

I don't have any experience in this but if you really need to load big files I suggest you do some kind of lazy loading with JTextPane/JEditorPane.

Define a limit that JTextPane/JEditorPane can handle well (like 500KB or 1MB). You'll only need to load a chunk of the file into the control with this size.

Start by loading the 1st partition of the file.

Then you need to interact with the scroll container and see if it has reached the end/beginning of the current chunk of the file. If so, show a nice waiting cursor and load the previous/next chunk to memory and into the text control.

The loading chunk is calculated from your current cursor position in the file (offset).

loading chunk = offset - limit/2 to offset + limit/2

The text on the JTextPane/JEditorPane must not change when loading chunks or else the user feels like is in another position of the file.

This is not a trivial solution but if you don't find any other 3rd party control to do this I would go this way.

bruno conde
A: 

Writing an efficient WYSIWYG text editor that can handle large documents is a pretty hard problem--Even Word has problems when you get into large books.

Swing is general purpose, but you have to build up a toolset around it involving managing documents separately and paging them.

You might look at Open Office, you can embed an OO document editor screen right into your app. I believe it's called OOBean...

Bill K
+1  A: 

You could use Memory Mapped File I/O to create a 'window' into the file and let the operating system handle the reading of the file.

Javamann