This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic