views:

46

answers:

2

Hi, I'm using a JTextPane to edit XML files. A jflex parser split xml file in tokens and using a custom document (extends DefaultStyledDocument) i color syntax:

doc.setCharacterAttributes(token.getCharBegin() + change, token.getCharEnd() - token.getCharBegin(), Token_Styles_Define.getStyle(token.getDescription()), true);

My problem is to load and edit large xml file, for exemple a 400kb xml file takes 30 seconds and for 700kb 1Mb i get java heap space. I google it and i found :

" 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)

Is this a good solution and can anybody give me an exemple (link tutorial project) ? or are any other solution? How can we improve jtextpane performance? Thx

A: 

A megabyte of text in a JTextPane should not be an issue. On my desktop, adding a 1MB string with setText() takes ~1.6 seconds, but once loaded there is no noticeable lag.

Try is disabling the syntax highlighting. That is the most likely source of the delay.

Devon_C_Miller
A: 

http://java-sl.com/JEditorPanePerformance.html May be this helps

Regards, Stas

StanislavL