Solved

Displaying lots of text

Posted on 2004-04-13
8
185 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 196
Java Loop 6 62
couple of eclipse 5 38
jboss wildfly 10.1 10 94
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

810 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