Solved

Displaying lots of text

Posted on 2004-04-13
8
184 Views
Last Modified: 2010-03-31
hi,

i'm new here but this is fairly urgent and any help would be much appreciated.

I'm trying to display the values of an array that can be have up to 50000 elements in it.  to do it, it iterate it in a loop and then add it to the component.  I've tried using textpanes, textareas etc. but they seem to be running VERY slowly and taking a long time to display the numbers.  I've even tried concatenating all the elements of the array into one string to display them, but thats just as slow.  does anyone have any solutions to make it appear as quickly as possible

cheers
0
Comment
Question by:Paul_Murphy
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10817253
Please post code
0
 
LVL 92

Expert Comment

by:objects
ID: 10817572
Add all your elements to a DefaultListModel and display using a JList
0
 
LVL 92

Expert Comment

by:objects
ID: 10817581
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 10817734
If all you're doing is displaying the elements, you can probably use Strings. Something like:

final int AVERAGE_ELEMENT_LENGTH = 10;
final int BUF_SIZE = 50 * 1000 * AVERAGE_ELEMENT_LENGTH; // or whatever
StringBuffer sb = new StringBuffer(BUF_SIZE);
for(int i = 0;i < yourArray.length;i++) {
      if (yourArray[i] != null) {
            sb.append(yourArray[i].toString());
            /*
             * if it contains primitives (also change
             * the above check to 0 instead of null)
             *
             * sb.append("" + yourArray[i]);
             */
      }
}      
yourComponent.setText(sb.toString());



0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10820387
If it is from a file then

Read the file using buffered reader.

BufferedReader reader = new BufferedReader(new FileReader(new File(<file name with path>)));
StringBuffer buffer = new StringBuffer();

String line  = null;
while ((line = reader.readLine()) != null)
      buffer.append(line);


textArea.setText(buffer.toString());

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10822082
8-)

With that StringBuffer, you'll get best performance from it if you always initialize it with a size slightly greater than you're going to need
0
 

Author Comment

by:Paul_Murphy
ID: 10822161
yeah, i've done that.  Thanks a million for the help
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10822175
No problem :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now