Java Platform, Standard Edition Deployment Guide
Contents    Previous    Next

6 JavaFX in Swing Applications

You can create Swing applications with embedded JavaFX content. This page describes how to deploy such applications.

This topic contains the following sections:

6.1 Overview

Developers working on existing Swing applications can take advantage of JavaFX features by integrating JavaFX content into their Swing applications. See the tutorial JavaFX and Swing Applications for more information.

Not all of the techniques discussed in this guide are applicable to Swing applications with JavaFX content, however, the following techniques are relevant:

  • The same packaging tools can be used to package your Swing applications.

  • The Deployment Toolkit can be used to embed your Swing application in a web page or launch it from a browser.

  • Your application can be bundled and packaged as an installable package, using the same technique as for self-contained applications.

Deployment of a Swing application with embedded JavaFX content on the web is similar to deployment of a regular Swing application as a Java Web Start application or applet. See the Java Tutorials lessons on Java applets and Java Web Start applications.

However, to use JavaFX, the deployment descriptor of your application (JNLP file) needs to express a dependency on the JRE.

Ant tasks are recommended for packaging hybrid applications, as described in Section 6.2, "Packaging with JavaFX Ant Tasks."). Alternatively, you can modify your existing packaging process manually, as described in Section 6.3, "Packaging without the Packaging Tools."

6.2 Packaging with JavaFX Ant Tasks

You can use same set of Ant tasks (see Chapter 5, "Packaging Basics") to package Swing applications with integrated JavaFX content. You only need to mark that the application's primary UI toolkit is Swing, using the toolkit="swing" attribute of <fx:application>.

The resulting package is similar to the package for pure JavaFX applications. See Section 5.2, "Base Application Package." The only difference is that there are two deployment descriptors - one for deploying as a Swing applet, and another for launching your application using Java Web Start.

Example 6-1 shows a sample Ant task for a Swing application that contains JavaFX code and uses the toolkit="swing" attribute.

6.3 Packaging without the Packaging Tools

If your project already has existing support for packaging as a Java Web Start application or applet, then it might be easier to modify the template of the JNLP file directly.

To express the dependency on the JavaFX Runtime, make the following changes in the JNLP file:

  • Define the JavaFX namespace with jfx:.

  • Specify that the minimum required version of the JRE is JRE 7 update 6 or later

Example 6-4 shows an example of these modifications to the deployment descriptor.

No changes are required on the HTML side. However, you can also use the Deployment Toolkit to integrate your content with the web page, as shown in the examples in the following sections.

6.3.1 Using the Deployment Toolkit

It is recommended that you use the Deployment Toolkit to deploy your application as an applet or launch it from a browser. The Deployment Toolkit simplifies deployment routines, such as ensuring that required JRE is available. The Deployment Toolkit also has several bonus features, such as:

For example, Example 6-5 shows web page code for launching a Swing Java Web Start application. This code is the same as that used to launch JavaFX applications.

Example 6-5 is simplistic, but you can use other features of the dtjava.launch() method in the Deployment Toolkit for Swing applications, as needed. For example, you can embed the JNLP file into the web page for faster startup.

For applets, the approach is similar. Applets can be embedded into a web page using the dtjava.embed() function. You must also specify the swing toolkit to indicate a preference of application type for the Deployment Toolkit.

Another caveat concerns built-in HTML splash support in the Deployment Toolkit. Swing applications do not have a default preloader, so there is no code to hide the HTML splash screen when the application is ready. To address this difference, use either of the following methods:

Contents    Previous    Next

Copyright © 1993, 2017, Oracle and/or its affiliates. All rights reserved.