Skip to main content

A suggestion for better text support

5 replies [Last post]
i30817
Offline
Joined: 2006-05-02
Points: 0

Swing becomes very slow when you try to use a large styled text (say 2mb) on the JEditorPane/JTextPane. Since my application supports it i've tried to evade this problem by creating a buffering solution for the JTextPane class, so that there are no more text views loaded at once than those that the interface needs.
I've failed. I needed to count the visible text length on the JTextPane view, but to do it i had to replace the paint method of the views, to update a shared variable that i'd use to get the length of the text. The problem was that the i couldn't reset the variable in all the situations when the variable went invalid, i don't know if due to my poor skills or due to the way that swing paints text.

My suggestion is this: add an utility method to the JText* classes to get the length of the visible text, or better yet, fix the text view model to do updates when invalidated. I think it would make swing more responsive.

Message was edited by: i30817

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
idk
Offline
Joined: 2005-01-12
Points: 0

Hi,

There are two places in this case where memory is consumed:
1. DocumentModel
2. Views hierarchy

DefaultStyleDocument has the document in memory plus Element hierarchy for it.
By default Views hierarchy has all the views ever needed to paint the document and to translate document position to screen and vice verse.

To implement memory efficient text support one is going to need to customize both.
Probably most memory efficient implementation is when there is only one Element per document and only one View to handle everything.

For plain text it is relatively simple task. For styled text it is going to be much more involved.
To optimize Views hierarchy I have heard people are using javax.swing.text.ZoneView. Is it something you have tried ?

Thanks,
Igor

i30817
Offline
Joined: 2006-05-02
Points: 0

Is not so much the memory that bothers me, (since i am holding a buffer of the entire document in memory) but, but the efficiency of the styled views, especially when the window is resized. I did try a while ago to replace the default boxview returned by the factory of the textpane with Zoneview, but it returned a exception IIRC.

Message was edited by: i30817

ovisvana
Offline
Joined: 2005-07-29
Points: 0

And while you are at it, how about better bidirectional text (bidi) support

Regards,
V.Omprakash
http://www.bonanzasoft.com

idk
Offline
Joined: 2005-01-12
Points: 0

Hi,

Do you have any specific requests in mind ?
What problems did you encounter ?

There are a number of BIDI related bugs in swing-text I am aware of. Interesting enough not that many people voted for them.

Thanks,
Igor

rbair
Offline
Joined: 2003-07-08
Points: 0

We were just talking about ideas for JXEditorPane this afternoon. Could you file an RFE for this in the swingx issue tracker so we don't lose track?

Thanks
Richard