Child pages
  • JFXPanel Bean

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Servoy 7.2 adds a new bean that supports integrating JavaFX user interface into Servoy. Currently the bean only works in Smart Client (Web Client will just display a dummy label). The bean needs Java 7 to run (both for developer and smart client) as since update 6 release JavaFX is bundled in Java install. In order to enable JavaFX support in jnlp (for Servoy Smart client), setting "servoy.client.javafx" must be set to true from admin page (default is false). If JavaFX is not enabled for Servoy Smart Client the bean will not work. The bean is actually a wrapper around JFXPanel component from JavaFX that is used to integrate JavaFX content into Swing. Along with its inherited methods the bean also has a javascript method: isJavaFXAvailable to determine if JavaFX install is available.

Sample Code

A small Hello World example of the bean:

...

titleHello World example
borderStylesolid

...

offers integration with JavaFX in the Smart Client, a new UI Toolkit for the Java platform.

The integration comes in the form of a low level JFXPanel bean, to which JavaFX UI components can be added through code. The API of the bean is inherited directly from JavaFX's JFXPanel class. A convenient .isJavaFXAvailable() method is added to check whether JavaFX is available or not.

Detailed information on the integration of JavaFX through the JFXPanel into Java Swing applications (which the Servoy Smart Client is), can be found in the JavaFX for Swing Developers tutorial of Oracle.

The most important thing to take into account when integrating JavaFX is that all interactions with the JavaFX components need to take place on the JavaFX User thread, while all interactions with the Servoy scripting layer need to place on Swing's Event Dispatch Thread (EDT). This means that working with JavaFX in Servoy solutions requires knowledge of Java and requires inline Java code.

Requirements

  • JavaFX is available on Windows, OSX and Linux as of Java 7 update 6, thus in order to use JavaFX the Smart Client or Servoy Developer (see notes) must be launched with Java 7 update 6 or higher. 
  • In order to enable JavaFX in a Smart Client running from a Servoy Application Server, the setting servoy.client.javafx on the Servoy Admin page must be set to true (Default is false)

Notes

  • The JFXPanel bean is Smart Client only, as JavaFX is a Java UI toolkit, thus it has no place in the Web Client or Mobile Client. In the Web Client the bean will render an empty panel
  • Running Servoy Developer on Java 7 on OSX is not as straight forward as it should be. See Running Servoy Developer on Java 7 on MAC OSX for more details

Simple sample

A small "Hello World" example using the bean:

Code Block
languagejs
borderStylesolid
titleHello World example
if (elements.myfxpanel.isJavaFXAvailable()) {
   var jsRunnable = {
  	run: function () {
  		var text = new Packages.javafx.scene.text.Text("Hello World");
  		text.setFont(new Packages.javafx.scene.text.Font(24));
  		var pane = new Packages.javafx.scene.layout.BorderPane(); pane.setCenter(text);
  		var scene = new Packages.javafx.scene.Scene(pane);
  		elements.myfxpanel.setScene(scene);
  	}
   }
   var runnable = new Packages.java.lang.Runnable(jsRunnable);
   Packages.com.sun.javafx.application.PlatformImpl.runLater(runnable);
}