File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Displaying a Huge Vector Quickly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Displaying a Huge Vector Quickly" Watch "Displaying a Huge Vector Quickly" New topic

Displaying a Huge Vector Quickly

Arann King

Joined: Jul 04, 2003
Posts: 2
I am trying to optimize the display time for a large (8000+ element) Vector.
Each element of the Vector contains an Array of Strings returned from a search on a XML document.
I am currently displaying the contents in a (JTextArea text), by iterating through the Vector start to finish and calling text.append("").
This process takes significantly longer than a SAX parser iterating through a 1 million line XML file.
Would it be quicker if I used a Hashtable and if so can they be dumped into any swing component? Is there any other way to quickly display a Vector in swing.
Thanks in Advance.
Abhik Sarkar
Ranch Hand

Joined: Jun 14, 2003
Posts: 61
How about appending everything to a StringBuffer and then calling setText on the JTextArea just once?
Arann King

Joined: Jul 04, 2003
Posts: 2
Hi thanks for the reponse,
I tryed using a StringBuffer and it is significantly faster however on repeated attempt I get a java.lang.OutOfMemoryError
I tried setting the Buffer to null after each search but to no avail.
Here is the extract
StringBuffer x = new StringBuffer();
for ( j = 0; j < tokens.length; j++) {
//casting object into a string array
a = (String[]) tokens[j];
//int t = j-1;
x.append("\n Result Number "+(j+1)+"\n");
for (int i = 0; i < a.length; i++) {
print = (String) a[i] + '\n';
//print =print +'\n'+ aa;
//print =print +'\n';
x.append("\n Number of Results = "+j);
x = null;
Any help appreciated.
I agree. Here's the link:
subject: Displaying a Huge Vector Quickly
It's not a secret anymore!