Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating JTextArea  RSS feed

 
roger berlandier
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's my problem, hoping someone might help...
I have a JTextArea that requires updating in "real time". I'm doing something like this:
for (int i=0;i<cmds.size();i++) {
String cmd = (String)cmds.elementAt(i);
display("\n"+cmd);
String result = execute(cmd);
jTextArea.append(result);
}
...but the problem is, my JTextArea is only being updated (or displayed) once the loop has completed. I think it may be due to the append() method for JTextArea being thread safe causing the update to be put at the end of the event dispatching thread (???).
Does anyone know how I can update it as soon as I invoke "append()"?
Thanks!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"RubberLand" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
to be sure that the append method runs in the swing thread, call it inside SwingUtilities.invokeLater.
See for example this article for more details:
http://www.smotricz.com/kabutz/Issue001.html
Chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!