Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Displaying lots of text

Posted on 2004-04-13
8
Medium Priority
?
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

636 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