Views
1 week ago

tornadofx-guide

Advanced Data Controls

Advanced Data Controls When you hard-code the width of the columns you will most likely end up with some extra space. This space will be awarded to the right most resizable column, unless you specify remainingWidth() for one or more column. In that case, these columns will divide the extra space between them. In the case where not all columns can be afforded their preferred width, all resizable columns must give away some of their space, but the SmartResize Policy makes sure that the column with the biggest reduction potential will give away its space first. The reduction potential is the difference between the current width of the column and its defined minimum width. Custom Cell Formatting in ListView Even though the default look of a ListView is rather boring (because it calls toString() and renders it as text) you can modify it so that every cell is a custom Node of your choosing. By calling cellCache() , TornadoFX provides a convenient way to override what kind of Node is returned for each item in your list (Figure 5.2). 200

Advanced Data Controls class MyView: View() { val persons = listOf( Person("John Marlow", LocalDate.of(1982,11,2)), Person("Samantha James", LocalDate.of(1973,2,4)) ).observable() } override val root = listview(persons) { cellFormat { graphic = cache { form { fieldset { field("Name") { label(it.name) } field("Birthday") { label(it.birthday.toString()) } label("${it.age} years old") { alignment = Pos.CENTER_RIGHT style { fontSize = 22.px fontWeight = FontWeight.BOLD } } } } } } } class Person(val name: String, val birthday: LocalDate) { } val age: Int get() = Period.between(birthday, LocalDate.now()).years 201

Guide
guide
GUIDE
GUIDE
GUIDE
Guide
Guide
guiding
GUIDE
guide
guide
Guide
Guide
GUIDE
GUIDE
GUIDE
Guide
Guide
The Guide
guide
Guide
guide
Guide
GUIDE TO
guide
GUIDE
GUIDE
GUIDE
GUIDE
guide