• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to display two JtestAreas contents alternatively handled by AWT-EventQueue-0 Thread

Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I'm developing Chat application GUI using SWING. My GUI has two JtestAreas one for displaying message that i was sent, and another for displaying replay coming from server. I was used Thread.sleep(1000) after message sent . Due to that, AWT-EventQueue-0 thread stops to display send message in first JtextArea and waits until it get response from server. After got response from server, in one shot, My GUI displays both JtetAreas Content.

But, I need to display send Message and Response Message in two different shots. I know the reason why it displays in one shot. Can I have solution from any one?

Thank you friends
Posts: 3063
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code that connects to the server needs to execute in a separate Thread.

Read the section from the Swing tutorial on Concurrency for more information. Maybe the SwingWorker is the best solution since it creates the Thread for you and you can just "publish" the server response as it becomes available and then update your GUI.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!