Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get hold of the EventDispatchThread  RSS feed

 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • 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 ]
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!