• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clearing JTextArea in EDT

 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Probably a pretty trivial issue but my last Swing project is some time ago... I have a test applcation using a JTextArea for the test output. I want to clear the area each time whena new test is carried out by pressing the Test button.
This Test button has an ActonListener and calls the test code and shows the result in the area. But as expected, the test area does not clear when the test runs (this can take several seconds) because the EDT blocks GUI update while running.
What is the best way to handle this? Calling the test code from an invokeLater thread?
TIA, Klaas
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either invokeLater, or preferably using a SwingWorker (since Java 6).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic