This repository has been archived by the owner on Sep 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 272
Extension Functions
Edvin Syse edited this page Feb 3, 2016
·
6 revisions
Wiki ▸ Documentation ▸ Extension Functions
As mentioned in Type Safe Builders, Kotlin already makes JavaFX code much easier to write and reason about. However, some parts of the JavaFX API could benefit from some extra love. This section describes some of the additions TornadoFX includes to make your code more consice.
// Take action when user selects a row
table.onUserSelect {
editCustomer(it)
}
// Take action when selection changes
table.onSelectionChange {
showCustomerDetails(it)
}
// Take action when user deletes row
table.onUserDelete {
deleteCustomer(it)
}
// Add column with valueProvider
table.addColumn<Customer, String>("Name") { it.value.name }
// Get selected item
val selected = table.selectedItem
// Configure updateItem for column
column.cellFormat { customer: Customer ->
text = customer.name
graphic = ImageView(customer.avatar)
}
// replace all children
pane.replaceChildren(newComponent1, newComponent2)
// Reload stylesheets (also valid for Scene)
pane.reloadStylesheets()
// Reload stylesheets on stage focus
stage.reloadStylesheetsOnFocus()
// Manipulate styleclasses
val isHeading = node.hasClass("heading")
node.addClass("heading")
node.removeClass("heading")
node.toggleClass("heading", predicate)
// Add Node to Pane, alternatives
node.addTo(pane)
pane += node
pane.add(node)
// Add row
pane.row {
label("Name")
textfield {
promptText = "Customer name"
addClass("big-input")
}
}
// Determine if event happened inside a TableRow
val isInside = event.isInsideTableRow()
// Convert a List to an ObservableList
val obs = list.observable()
Next: JsonModel