Solved

Displaying lots of text

Posted on 2004-04-13
8
183 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

758 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

18 Experts available now in Live!

Get 1:1 Help Now