groovyfx-project / groovyfx

A library for writing JavaFX 8 applications in the Groovy language.
http://groovyfx.org
Apache License 2.0
199 stars 48 forks source link

How to start GroovyFX from JavaFX #69

Open wise-coders opened 2 weeks ago

wise-coders commented 2 weeks ago

I already have a JavaFX application, with an embedded text editor. The editor is using something like this to execute the script I paste inside.

final GroovyShell shell = new GroovyShell( new GroovyConfig(  ) );
final Script script = shell.parse( query, binding );

If I paste the demo below and execute it, I get this error: Application launch must not be called more than onece.

How can I avoid this?

import groovyx.javafx.GroovyFX;

GroovyFX.start {
    stage(x: 100, y: 100, onShown: { println "Stage 1" }, visible: true, style: 'UTILITY') {
        scene(width: 100, height: 100, fill: GROOVYBLUE)
    }
    stage(primary: false, x: 100, y: 400, visible: true) {
        onShown { println "Stage 2" }
        scene(width: 100, height: 100, fill: RED)
    }
}