To create a new Task we would code:
Task<String> taskInstance = new Task<String>() {
@Override
protected String call() throws Exception {
// Do something expensive here
Platform.runLater(() -> {
// Code to be executed on main thread goes here
});
return "Done!";
} // End of call
}; // End of new Task()
JavaFX CSS and Stylesheets
The JavaFX controls can be styled using stylesheets. We can load a stylesheet using the
"stylesheets" attribute applied to a container. To use this attribute, we would code:
<SomeContainer>
<stylesheets>
<URL value="@<name>.css"/>
</stylesheets>
</SomeContainer>
The CSS properties for a control all start with "-fx-" to indicate that they are JavaFX as opposed
to web. The JavaFX CSS reference provides all the details of the properties available. Some of the
more common are:
• -fx-text-fill – The color of the text
See also:
• JavaFX CSS Reference
JavaFX Deployment
Once an application utilizing JavaFX has been built in Eclipse or some other tool, the next thought
is that of deployment. Deployment is sequence of steps necessary to make the application available
for users to use.
The deployment tools generate three primary artifacts.
• A JAR file – This JAR contains the compiled code and other resources necessary to execute
the application.
• A JNLP file – This file allows the application to be deployed from a Java Web Start
environment.
• An HTML file – This file provides a template to launch the app in a web page.
If we wish to create a Windows "msi" installer, we will need to install the Wix Toolset
(http://wixtoolset.org/).
If we wish to create an EXE installer, we need to install Inno Setup Compiler )
To build a deployable solution we follow three primary steps.
The first is to get our application the way we want it. With this done, we extract all the compiled
classes and resources into its own directory … for example a directory called "bin". Eclipse does
this for us … there is a directory called "bin" next to our "src" folder.
With a directory containing our compiled code and resources, we now use a tool called
Page 265
Comentários a estes Manuais