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-2.0.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.

Using JavaFX with JDK 7

JDK 8 ships with JavaFX, and it is in the default CLASSPATH. JDK 7 update 9 or later does have JavaFX included, but it is a separate jfxrt.jar which not in the default CLASSPATH. Thus you have to explicitly add jfxrt.jar. To run the previous HelloButton1.scm you can do:

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