GraalVM Native Image Demo - JFace and Draw2D


Draw2D is a lightweight layout and rendering toolkit building on top of SWT. It may not as powerful as Java Swing or JavaFX, it’s very useful for displaying graphical components. This article will show you how to build a stand-alone native Java application with JFace and Draw2D, and GraalVM native image.

Setting Up JFace

While SWT is great for building Java GUI with native look and feel, it would be tedious for complex application. JFace provides a set of reusable components that make it easier. and it can be used for developing a stand-alone application. Detailed step-by-step instructions are available in the Setting Up an Eclipse Project to use SWT and JFace section of the JFace article.

For this demo, you don’t need do that:

  1. Download jface.standalone and import it via menu File -> Import…, select General -> Existing Projects into Workspace.
  2. Create a new variable called RCP_HOME, if you are using Eclipse 4.18, RCP_HOME is same as ECLIPSE_HOME.
  3. Otherwise, download Eclipse RCP 4.18, unzip it to a folder, then set RCP_HOME to that folder.

Draw2D and Zest

Draw2D is a layout and rendering toolkit building on top of SWT. It may be used standalone (outside of Eclipse) or in combination with the GEF or Zest component. Unfortunately, GEF 3 need Eclipse RCP, and I don’t think GraalVM native image is able to handle Eclipse RCP yet. GEF 5 is able to run as stand-alone application, but somehow build on JavaFX and only.

This demo will only using zest for layout and animation. The Web Design 28 SVG Vector Collection and Icons were used for demonstration.

Setting Up GEF

  1. Download GEF Legacy 4.0.0, unzip it to a folder, then create a new variable called GEF_HOME to that folder.
  2. Download GEF project and import it via menu File -> Import…, select General -> Existing Projects into Workspace.

Draw2D and Skija

To use Skija the Java binding for Skia in Draw2D, download Skija for aarch64 and import it via menu File -> Import…, select General -> Existing Projects into Workspace.

Source code and binary

Source and binary for Raspberry Pi OS 64.

./build.sh
./run -trace
./build -native

Conclusion

This is just a quick hack to test GraalVM native image, a lot of things need to rewrite to use more advance features of Skia Graphics Engine.