wood burning stoves 2.0*
The moose likes JavaFX and the fly likes Thread and UI (Application) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Thread and UI (Application) "communication"" Watch "Thread and UI (Application) "communication"" New topic
Author

Thread and UI (Application) "communication"

L Purcell
Greenhorn

Joined: Feb 19, 2012
Posts: 12
Here's the scenario: A "start" button is clicked which sets up a Service/Task which includes I/O with a device. A changeListener is started, and the "start" button handler ends. Eventually, the changeListener detects a "change" and does its thing with the I/O device. NOW my question: How do I "notify" the user that the "change" (event) has occurred? "Update message" doesn't do anything since the "start" button routine has ended. I know I'm missing something fundamental here, but I'm baffled. (This is my first foray into the Service/Task business...) (The code in all other respects works great.) Thanks! L (Here is the boiled-down code.)

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

This is an interesting scenario. The usual examples for tasks have a blocking task happening within the Task and so updation of GUI can be done. But, in this case, you just register a callback handler. Actually, in this case, you may not need the task to just install the listener.
And from within the listener, You can wrap the UI update call in Platform.runLater()


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
L Purcell
Greenhorn

Joined: Feb 19, 2012
Posts: 12
Ranga, thanks for the reply. I decided to keep the service/task since the setup part (which I omitted to save space) may hang/block. However, I solved the "communication" problem by BINDING the text in a textArea with the messageProperty in the Task! Perhaps this has the same effect as you were suggesting (by different means)?? Anyway, it all appears to work now, and I'm off struggling with the Android client code... Thanks again! L
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

Ok, I see where the task was needed. I am not sure about the binding, because, I have never tried it myself - that sounds interesting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread and UI (Application) "communication"
 
Similar Threads
Null pointer exception probably due to synchronisation issues; problem in starting activity
JavaFX, Scene Builder, and basic issues with threads/tasks
javafax, button action..NEED HELP PLEASE!!!
USB Modem stuck while submitting data
Need help with thread pool issue..