• Post Reply Bookmark Topic Watch Topic
  • New Topic

can't get value of JTextFiled after running thread  RSS feed

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm asking in behalf of somebody else so I don't have access to the source code. I'd just like to ask if you're familliar with this problem. I have a JTextField. I get the value in the run() method of the Runnable interface(implemented). After that, I try to access the value of the JTextField again but this time, althogh there is a text displayed. When I print the value of the textbox nothing is printed. Any clues? Is this a thread problem? Thanks!
 
Paul Clapham
Sheriff
Posts: 22379
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "a thread problem". It's a programming problem. If there's data in the JTextField, and you don't see it when you print it, then you are printing something else.
 
Henry Wong
author
Sheriff
Posts: 23282
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once a component is active, it should not be accessed by any thread other than the event dispatching thread. Accessing with another thread will yield mix results.

To run some code in the event dispatching thread, you can use the SwingUtilities class. There is a method that will allow you to invoke code and wait for the result. Your code can simply get the text field value, and store it somewhere else for the original calling thread.

Henry
 
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!