This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Clearing JTextArea in EDT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Clearing JTextArea in EDT" Watch "Clearing JTextArea in EDT" New topic
Author

Clearing JTextArea in EDT

Klaas van Gelder
Ranch Hand

Joined: Jul 08, 2004
Posts: 100
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

"What you don't know, can't help you"
SCJP (81%), SCWCD (81%), SCJD (354/400), SCBCD (85%)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Either invokeLater, or preferably using a SwingWorker (since Java 6).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clearing JTextArea in EDT
 
Similar Threads
General question about ActionListeners accessing other GUI elements
How to reassign STDIN to a JTextArea??
How to update JTextField from child thread?
Finding current line number - textarea
2 Simple JTextAreas with a button