• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get hold of the EventDispatchThread

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have created a UI class (a JPanel).I have a ComboBox in this UI that shows the Name of all the available objects. When creating a new object from this Panel, it sends a message to SERVER and creats the object in DataBase. The Server replies to the above request with either SUCCESS or FAIL.
If the reply is SUCCESS then I have to update the ComboBox with the name of the new Object.

Problem: The message that I am sending to Server internally creates a timertask and sends message to server. The UI is getting updated before the response is coming back from SERVER. I have to make the EventDispatchThread to wait till it gets response from the server. How do I do this?
[ February 23, 2008: Message edited by: Karthick Dharani Vidhya ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have to make the EventDispatchThread to wait till it gets response from the server. How do I do this?



You don't. Having the event dispatching thread wait (for anything) is basically having the GUI wait. You don't want to cause the GUI to freeze.

To solve it, you have to remove the part of the code that updates the combo box. Place this code into a runnable object. And then, in your timer task, when you get the response from the server, instantiate and register this runnable object to be executed by the event dispatching thread. (See the SwingUtilites class for info on how to do this)

Henry
[ February 23, 2008: Message edited by: Henry Wong ]
reply
    Bookmark Topic Watch Topic
  • New Topic