Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get JTextArea to show input as it is being added?

 
myron schabe
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Want I want to do is have a JTextArea display strings as it is being added - sort of like showing progress. The code snippet I have below just (visually)dumps the contents into the text area when the loop is completed. What I want is the JTextArea to visually add the strings line by line as it is looping - so a user know that something is going on rather than a big long wait then a dump. Of course, setText() vs. append() doesn't work either as that doesn't concatentate. Validates or repaints don't seem to help. I am missing something. I can use another widget if it provides the desired affect.
JTextArea textArea = new JTextArea();
for(int i = 0; i <= 10000; i++)
{
textArea.append("blah blah blah blah...\n"); textArea.validate();
scrollPane.validate();
}

Many Thanks!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to add each line in a separate thread... something like this...

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic