Fork me on GitHub

GroovyFX

The easiest way to write JavaFX 8 applications in Groovy.

GroovyFX provides a Groovy binding for JavaFX 8.

GroovyFX is an API that makes working with JavaFX in Groovy much simpler and more natural. GroovyFX is focused on exploiting the power of the Groovy Builder pattern to make JavaFX development easier and more concise than what is possible in Java. GroovyFX also leverages Groovy's powerful DSL features and AST transformations to eliminate boilerplate, making GroovyFX code easier to write and, just as importantly, easier to read.

GroovyFX provides the SceneGraphBuilder object, which supports all of the JavaFX controls, shapes, gradients, effects, and animation; as well as other elements of the JavaFX API such as enumerations and colors. Additionally, Groovy closures can be used as event handlers, leading to clean and concise code.

Hello, World

A simple and complete "Hello, World" program is shown below. The general pattern for a GroovyFX application is to define the JavaFX components within a Groovy closure that is passed to the static start method of the GroovyFX class. Inside this closure, we simply start declaring our JavaFX scene graph nodes.

Each JavaFX class has a corresponding GroovyFX node. For example, the JavaFX Stage class becomes the stage node. All GroovyFX node names are exactly the same as their JavaFX counterparts with the start of their class names converted to lowercase letters.


import static groovyx.javafx.GroovyFX.start

start {
    stage(title: 'GroovyFX Hello World', visible: true) {
        scene(fill: BLACK, width: 500, height: 250) {
            hbox(padding: 60) {
                text(text: 'Groovy', font: '80pt sanserif') {
                    fill linearGradient(endX: 0, stops: [PALEGREEN, SEAGREEN])
                }
                text(text: 'FX', font: '80pt sanserif') {
                    fill linearGradient(endX: 0, stops: [CYAN, DODGERBLUE])
                    effect dropShadow(color: DODGERBLUE, radius: 25, spread: 0.25)
                }
            }
        }
    }
}

The result of running this program is shown in the image below. See the Getting Started section of the user guide for more information.

GroovyFX Hello World

License

GroovyFX is licensed under the Apache License, Version 2.0.

Download

You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/groovyfx-project/groovyfx