Skip to content

Instantly share code, notes, and snippets.

@exallium
Created January 14, 2016 19:29
Show Gist options
  • Save exallium/243f31b1d822516c0a11 to your computer and use it in GitHub Desktop.
Save exallium/243f31b1d822516c0a11 to your computer and use it in GitHub Desktop.
JavaFX Button Column Creation in Kotlin
public fun <T> createButtonColumn(title: String, text: String, onClick: (T) -> Unit): TableColumn<T, T> {
val buttonColumn = TableColumn<T, T>(title)
buttonColumn.cellValueFactory = Callback { ReadOnlyObjectWrapper<T>(it.value) }
buttonColumn.cellFactory = Callback {
val button = Button()
object : TableCell<T, T>() {
override fun updateItem(item: T?, empty: Boolean) {
super.updateItem(item, empty)
if (item == null) {
graphic = null
} else {
button.text = text
button.onAction = EventHandler<ActionEvent> {
onClick(item)
}
graphic = button
}
}
}
}
return buttonColumn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment