Overview
JavaFXWorker is a SwingWorker equivalent for JavaFX Script to allow execution of asynchronous operations in the background with notification and completion callbacks on the Event Dispatch Thread (EDT).
Here is an example that will load an Image and set it to a variable when the load is completed:
var currentImage:Image;
var worker = JavaFXWorker {
inBackground: function() {
return Image {url: currentFile.toURL().toString(), height: imageHeight};
}
onDone: function(result) {
currentImage = result as Image;
}
}
Both the inBackground and onDone handlers are required to be set. Upon initialization the worker will automatically start execution on a background thread and can be later stopped by calling cancel. Any results of execution in the background thread will be saved to the result var and also passed in to the onDone handler.
Profile: desktop
Variable Summary
| access | name | type | Can Read | Can Init | Can Write | Default Value | description |
|---|---|---|---|---|---|---|---|
| public-read | cancelled | Boolean | ![]() |
A read-only variable that indicates if this worker has been cancelled by calling the cancel() function.
A read-only variable that indicates if this worker has been cancelled by calling the cancel() function. Should be used to break out of any background processing loops so the task ends promptly. |
|||
| public-init protected | inBackground | function():Object | ![]() | ![]() | subclass |
Function that will be executed on a background thread.
Function that will be executed on a background thread. If an exception is thrown while executing this function the failed var will be set to true and failedText will be set to the exception message. Since this method is executed asynchronous to other UI operations, it is not safe to make calls that will modify the UI state. This includes most JavaFX Script library operations. |
|
| public-init protected | onDone | function(:Object):Void | ![]() | ![]() | subclass |
Function that will be called once inBackground completes.
Function that will be called once inBackground completes. The result of the background function will be passed in to the result parameter when this function is called. This function is guaranteed to be called on the Event Dispatch thread, and can safely make changes to the UI state. |
|
| public-init protected | onFailure | function(:ExecutionException):Void | ![]() | ![]() | subclass |
Function that will be called if inBackground fails due to an exception.
Function that will be called if inBackground fails due to an exception. The exception is passed in as a parameter when this function is called, and the attributes failed and failureText will be set to 'true' and the message of the exception, respectively. This function is guaranteed to be called on the Event Dispatch thread, and can safely make changes to the UI state. This var may be left null if no special handling of exceptions is required. |
|
| public-init protected | process | function(:Sequence):Void | ![]() | ![]() | subclass |
This function is called on the event dispatch thread to process incremental data from the publish method.
This function is called on the event dispatch thread to process incremental data from the publish method. Multiple invocations of publish may occur before this method is called, and the list of data passed in will be the aggregated values from all the publish calls. Since this function is guaranteed to be called on the Event Dispatch thread, you can safely make changes to the UI state. |
|
| public-read | result | Object | ![]() |
This var gets set to the result returned by the inBackground method if it is successful, and will also be passed in to the onDone handler. |
Inherited Variables
Function Summary
- public cancel() : Void
- public publish(data: java.lang.Object[]) : Void

