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 get instance of Application object? #53

Open novakmi opened 7 years ago

novakmi commented 7 years ago

Sometimes it is necessary to have access to the instance of Application. For example to call getHostServices() or getParameters(). Is there any way to do it? Seems like GroovyFX hides this instance completely.

andreas-oberheim commented 6 years ago

You may just use the closure parameter of type groovyx.javafx.GroovyFX

Sample groovy class:

import static groovyx.javafx.GroovyFX.start

start { app ->

    stage(title: 'GroovyFX web site', width: 500, height: 200, show: true) {
        scene(fill: groovyblue) {
            stackPane {
                button('GroovyFX web site', onAction: {
                    def js = app.hostServices.showDocument('http://groovyfx.org/')
                })
            }
        }
    }
}
novakmi commented 6 years ago

Thanks, it works :-) I was not aware app can be added to start closure.