Skip to content

Instantly share code, notes, and snippets.

@bjonnh
Created April 25, 2018 22:30
Show Gist options
  • Save bjonnh/42dcbe3e6ecb27452780fd12d851b011 to your computer and use it in GitHub Desktop.
Save bjonnh/42dcbe3e6ecb27452780fd12d851b011 to your computer and use it in GitHub Desktop.
import javafx.application.Application
import javafx.beans.property.SimpleIntegerProperty
import javafx.scene.control.Button
import javafx.scene.layout.VBox
import tornadofx.*
import java.time.LocalDate
import java.time.Period
class Person(id: Int, name: String, birthday: LocalDate) {
var id by property(id)
fun idProperty() = getProperty(Person::id)
var name by property(name)
fun nameProperty() = getProperty(Person::name)
var birthday by property(birthday)
fun birthdayProperty() = getProperty(Person::birthday)
// val age: Int get() = Period.between(birthday, LocalDate.now()).years
val age: SimpleIntegerProperty get() = SimpleIntegerProperty(Period.between(birthday, LocalDate.now()).years)
}
private val persons = listOf(
Person(1,"Samantha Stuart",LocalDate.of(1981,12,4)),
Person(2,"Tom Marks",LocalDate.of(2001,1,23)),
Person(3,"Stuart Gills",LocalDate.of(1989,5,23)),
Person(3,"Nicole Williams",LocalDate.of(1998,8,11))
).observable()
class MyView : View() {
override val root = VBox()
init {
with(root) {
Button("Press Me")
Button("Foo")
tableview(persons) {
isEditable = true
column("ID",Person::id).makeEditable()
column("Name", Person::name).makeEditable()
val birthday = column("Birthday", Person::birthday).makeEditable()
val age = column("Age", Person::age)
}
}
}
}
class MyApp: App(MyView::class)
fun main(args: Array<String>) {
Application.launch(MyApp::class.java, *args)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment