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)
(javafx-application)

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

JDK 7 update 9 or later has JavaFX included, but it is a separate jfxrt.jar which not in the default CLASSPATH. JavaFX support is builtin to the pre-built kawa-1.14.jar. Assume the above file is HelloButton1.scm, you can run it like this:

java -cp $JAVA_HOME/lib/jfxrt.jar:$KAWA_HOME/kawa.jar HelloButton1.scm

If you build Kawa from source, do:

$ ./configure --with-javafx=$JAVA_HOME --enable-kawa-frontend ...other-args...

The resulting Kawa binary sets up the path to jfxrt.jar so you just need to do:

$ kawa HelloButton1.scm

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