• 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

Reading JTextField Using AWT Event Queue

 
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I am making a request to read a value in a JTextField using tthe AWT Event Queue and storing it in a local variable, the value is not immediately available. I have to wait somehow to know it has been written from the Even Dispatch Thread to the local variable before using it in another thread. I am not sure how to synchronize this. Does anyone have a tip to point me in the right direction?
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It all depends on what the purpose of this is.
A couple of possible solutions are:
1. You could have your other thread use EventQueue.invokeAndWait to get the value from the JTextField.
2. You could write the value into a BlockingQueue on the event thread and have the other thread call the queue's take() method to get/wait for the value.

Note these are just 2 possible solutions I picked at random, if you can give full details of what you are trying to achieve we may be able to suggest a better solution for your scenario.
 
Mack Wilmot
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, invokeAndWait will work! I have not used that before, only invokeLater. Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic