The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Very Large Strings in JTextArea

Posted by Matt Gerrans on November 09, 2001 at 12:46 PM

> i had also problems when viewing a String (24MB) in a JTextArea component. The method setText() always crashes the JVM. Then I tried the read() method from the JTextArea and it works, but it consumes a lot of Memory!

I think this is one of those cases where the answer is: Don't do it!

Even if it didn't crash, how would anyone make use of 24MB of text in a text area? It would be more effective to create your own VirtualJTextArea object, that works like a virtual listbox in Windows. Rather than actually stick all the data in the conrol, you use the control (JTextArea) as a moving "window" into your huge chunk of data. As that "window" is moved by the user, you display different parts of your data in it. For such a large piece of data, you might also want to provide some navigation tools with better conrol than JScrollPane. Additionally, using this scheme, you never have to load the whole thing into memory at once; you can read only the part that the use is looking at (plus a bit of look-ahead cache, to boot).

- mfg


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us