Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Update textarea controle from inside a thread  RSS feed

 
John Devlon
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

I would like to update a JTextArea on a JFrame from within a external thread... Does somebody know how to do this? Some people recommand using Swingworker, others mention Eventlistener, SwingUtilities.InvokeLater() or EventQueue.InvokeLater()...

Frame code...


Class


How do I change the code from printing to the console, to appending the text to my JTextArea on my form... ?

Thanks
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to be careful when you mix multiple threads with GUIs. It's a tricky business. So just a quick answer like "Use SwingWorker" isn't going to be good enough. Instead I suggest you check out the tutorial. It comes with examples, which I suggest you should model your code on.
 
John Devlon
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your feedback. I reviewed the code of the Flipper.java example file, posted on the site. This is a great example.

However, the example file has the SwingWorker extended class embedded in the swing class. So connecting to the swing elements is no problem. But what if I want to update a swing element from a external class file? Do I pass the swing form object to the threaded class to be able to update the form elements or is there a better approach?

Thanks

John
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!