Building JavaFX applications

Kawa makes it easy to build “rich client” (i.e. GUI) applications using JavaFX. For example the following program will print up a window with a button; clicking on the button will print a message on the console output about the event.

(require 'javafx-defs)

 title: "Hello Button"
 width: 600 height: 450
  text: "Click Me"
  layout-x: 25
  layout-y: 40
  on-action: (lambda (e) (format #t "Event: ~s~%~!" e))))

JavaFX support is builtin to the pre-built kawa-3.1.1.jar. It is easiest to use JDK 8; see below if you’re using JDK 7. If you build Kawa from source, specify --with-javafx on the configure command line (assuming you’re using JDK 8).

Assume the above file is HelloButton1.scm, you can run it like this:

$ kawa HelloButton1.scm

For more information and examples read this (slightly older) introduction, and this on animation.

The browse-kawa-manual script in the doc directory (source only) uses JavaFX WebView to create a window for browsing the Kawa documentation.

Using JavaFX with JDK 11+

Starting with JDK 11, JavaFX has been moved to a separate project and is no longer included in the JDK. The separate project OpenJFX provides an SDK that includes modular jar files which can be added to the CLASSPATH or via the --module-path parameter to javac and java.

To run the previous HelloButton1.scm you can do:

$ java -cp $KAVA_HOME/kawa.jar --module-path $JAVAFX_HOME/lib \
  --add-modules javafx.web HelloButton1.scm

If you build Kawa from source you must use an appropriate JDK version and enable the modular OpenJFX SDK:

$ ./configure --with-javafx=path-to-sdk ...other-args...

The resulting Kawa binary sets up the module path and the boostrap module so you just need to do:

$ kawa HelloButton1.scm