Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Application Startup

Edvin Syse edited this page Apr 28, 2016 · 9 revisions

WikiDocumentationApplication Startup

Application Startup

To define the entrypoint for your application, you extend the tornadofx.App class, which in turn extends javafx.application.Application. The only property you need to override is the reference to your primary view:

class HelloWorldApp : App() {
    override val primaryView = MyMainView::class
}

IntelliJ IDEA Users: Make sure you create an Application run configuration, not a Kotlin run configuration.

It is also customary to load stylesheets in the init block of the App class:

init {
    // Import a file based stylesheet
    importStylesheet("/style.css")

    // Import a type safe stylesheet
    importStylesheet(Styles::class)
}

Startup Parameters

Override start() or any other function that comes after it in the life cycle to access command line arguments. If you start your app with --myoption=myvalue you can access it via the parameters getter:

override fun start(stage: Stage) {
    val myoption = parameters.named["myoption"]
}

You can further override any JavaFX Lifecycle method if it fits your needs.

Built-in startup parameters

You can control certain parts of the framework by adding some program parameters. These parameters should only be used in development and will only work when you've attached a debugger. The following table shows all the program parameters, their programmatic counterpart and description:

Parameter Programmatic counterpart Description
--live-stylesheets reloadStylesheetsOnFocus() Stylesheets will be reloaded whenever the Stage gains focus.
--dump-stylesheets dumpStylesheets() Stylesheets will be printed to stdout when they are loaded or reloaded.
--live-views reloadViewsOnFocus() Views will be reloaded whenever the Stages gains focus. State can be transferred via ViewContainer.pack()/unpack().
--dev-mode All of the above Enable all the developer functions with a single parameter.

If you don't want to use the program parameters, it's a good practice to call these functions from the init block of your App class.

Application Instance

The actual application instance is available in the global variable FX.application. This can come in handy if you need to reference the application, like for example when getting an instance of the HostServicesFactory.

Next: Integrate with existing JavaFX Applications

Clone this wiki locally