3. Components fun editCustomer(customer: Customer) { } find(mapOf(CustomerEditor::customer to customer).openWindow()) The parameters are passed as a map, where the key is the property in the view and the value is whatever you want the property to be. This gives you a type safe way of configuring parameters for the target View. Here we use the Kotlin to syntax to create the parameter. This could also have been written as Pair(CustomerEditor::customer, customer) if you prefer. The editor can now access the parameter like this: class CustomerEditor : Fragment() { } val customer: Customer by param() If you want to inspect the parameters instead of blindly relying on them to be available, you can either declare them as nullable or consult the params map: class CustomerEditor : Fragment() { init { val customer = params["customer"] as? Customer if (customer != null) { ... } } } If you do not care about type safety you can also pass parameters as mapOf("customer" to customer) , but then you miss out on automatic refactoring if you rename a property in the target view. Accessing the Primary Stage View has a property called primaryStage that allows you to manipulate properties of the Stage backing it, such as window size. Any View or Fragment that were opened via openModal will also have a modalStage property available. Accessing the Scene 28
3. Components Sometimes it is necessary to get a hold of the current scene from within a View or Fragment . This can be achieved with root.scene , or if you are within a type safe builder, just call scene . Accessing Resources Lots of JavaFX APIs takes resources as a URL or the toExternalForm of an URL. To retrieve a resource url one would typically write something like: val myAudioClip = AudioClip(MyView::class.java.getResource("mysound.wav").toExternalFo rm()) However, every Component has a resources object which can retrieve the external form url of a resource like this: val myAudiClip = AudioClip(resources["mysound.wav"]) If you need an actual URL , it can be retrieved like this: val myResourceURL = resources.url("mysound.wav") The resources helper also has several other helpful functions to help you turn files relative to the Component into an object of the type you need: val myJsonObject = resources.json("myobject.json") val myJsonArray = resources.jsonArray("myarray.json") val myStream = resources.stream("somefile") It is worth mentioning that the json and jsonArray functions are also available on InputStream objects. Resources are relative to the Component but you can also retrieve a resource by it's full path, starting with a / . Summary TornadoFX is filled with simple, streamlined, and powerful injection tools to manage Views and Controllers. It also streamlines dialogs and other small UI pieces using Fragment . While the applications we built so far are pretty simple, hopefully you appreciate the simplified 29
6. Type Safe CSS label("Lore Ipsum"
6. Type Safe CSS If you want the bu
6. Type Safe CSS import javafx.scen
6. Type Safe CSS Modifier Selection
6. Type Safe CSS The DangerButtonSt
7. Layouts and Menus vbox { button(
7. Layouts and Menus Notice also wh
7. Layouts and Menus borderpane { l
7. Layouts and Menus 95
7. Layouts and Menus The example ab
7. Layouts and Menus One way to use
7. Layouts and Menus columnIndex: I
7. Layouts and Menus TabPane A TabP
7. Layouts and Menus Like many buil
7. Layouts and Menus Separators You
7. Layouts and Menus Note there are
7. Layouts and Menus Attribute Buil
7. Layouts and Menus item("SomeText
7. Layouts and Menus squeezebox { f
7. Layouts and Menus class DrawerVi
7. Layouts and Menus drawer(side =
8. Charts Charts JavaFX comes with
8. Charts val items = listOf( PieCh
8. Charts In the series() and data(
8. Charts Multiseries You can strea
8. Charts BubbleChart BubbleChart i
8. Charts Summary Charts are a an e
9. Shapes and Animation class MyVie
9. Shapes and Animation CubicCurve
9. Shapes and Animation Polyline A
9. Shapes and Animation Path Path r
9. Shapes and Animation A KeyValue
9. Shapes and Animation If you want
10. FXML If you are converting an e
10. FXML We have created an FXML fi
10. FXML class CounterView : View()
10. FXML FXML is helpful to know as
11. Editing Models and Validation F
11. Editing Models and Validation }
11. Editing Models and Validation p
11. Editing Models and Validation T
11. Editing Models and Validation /
11. Editing Models and Validation m
11. Editing Models and Validation L
11. Editing Models and Validation -
11. Editing Models and Validation F
11. Editing Models and Validation E
11. Editing Models and Validation d
11. Editing Models and Validation i
12. TornadoFX IDEA Plugin 13. Torna
12. TornadoFX IDEA Plugin You will
12. TornadoFX IDEA Plugin A generat
12. TornadoFX IDEA Plugin Injecting
12. TornadoFX IDEA Plugin Generatin
12. TornadoFX IDEA Plugin You will
Part 2: TornadoFX Advanced Features
Property Delegates class MyView: Vi
Property Delegates class Bar { var
Advanced Data Controls Advanced Dat
Advanced Data Controls This fine-tu
Advanced Data Controls This setting
Advanced Data Controls class MyView
Advanced Data Controls Assign If Nu
Advanced Data Controls 205
OSGi The dynamic nature of OSGi len
OSGi class Dashboard : View() { ove
OSGi Requirements To run TornadoFX
Scopes Scopes Scope is a simple con
Scopes Now whenever you access the
Scopes Testing with Scopes Since Sc
EventBus A button in the UI can fir
EventBus When you create a subclass
EventBus Many feel that events migh
Workspaces Workspaces Java Business
Workspaces To keep things focused,
Workspaces fun TabPane.connectWorks
Workspaces Modifying the default wo
Workspaces Title and heading When a
Workspaces Navigating between docke
Workspaces We can see that the titl
Workspaces workspace.dockInNewScope
Workspaces A Workspace in Tabs mode
Workspaces // A Form based View we
Workspaces This could be a good ide
Layout Debugger Layout Debugger Whe
Layout Debugger yet, submit a pull
Internationalization You can add a
Config Settings and State Config se
Config Settings and State If the re
Config Settings and State var bool:
JSON and REST } } with(json) { add(
JSON and REST Basic operations Ther
JSON and REST To configure authenti
Dependency Injection Dependency Inj
Dependency Injection This initializ
Wizard class BasicData : View("Basi
Wizard When the Next or Finish butt
Wizard val wizard = find() wizard.s
Wizard class CustomerWizard : Wizar
Wizard Structural modifications The