enum class SchoolType { UNDERGRADUATE, GRADUATE, POSTGRADUATE } class Student(id : Long, name : String, school : SchoolType ) { val idProperty = SimpleLongProperty(id) val nameProperty = SimpleStringProperty(name) val schoolProperty = SimpleObjectProperty(school) } class StyleTestView : View() { val students = listOf( Student(1L, "Robert", SchoolType.UNDERGRADUATE), Student( 2L, "James", SchoolType.UNDERGRADUATE), Student( 3L, "Carl", SchoolType.POSTGRADUATE) ).observable() override val root = vbox { addClass(Styles.container) label("Students") tableview(students) { column("ID", Student::idProperty) column("Name", Student::nameProperty) column("School", Student::schoolProperty) columnResizePolicy = CONSTRAINED_RESIZE_POLICY vgrow = Priority.ALWAYS rowFactory = Callback { object : TableRow() { override fun updateItem(item: Student?, empty: Boolean) { super.updateItem(item, empty) if( item != null ) { when(item.schoolProperty.value) { SchoolType.UNDERGRADUATE -> addClass(Styles.undergraduate) SchoolType.GRADUATE -> addClass(Styles.undergraduate) SchoolType.POSTGRADUATE -> addClass(Styles.postgraduate) else -> { } // ignore } } } } } } separator() hbox { label("Num Components:") { addClass(Styles.statusLabel) } textfield() padding = Insets(4.0) spacing = 4.0 alignment = Pos.CENTER_LEFT } prefWidth = 800.0 prefHeight = 600.0 padding = Insets(4.0) alignment = Pos.TOP_LEFT } } class StyleTestApp : App(StyleTestView::class, Styles::class) { init { reloadStylesheetsOnFocus() } } class Styles : Stylesheet() { companion object { val container by cssclass() val statusLabel by cssclass() val undergraduate by cssclass() val graduate by cssclass() val postgraduate by cssclass() } init { container { backgroundColor += Color.SKYBLUE } label { fontSize = 16.px } statusLabel { fontSize = 12.px } // .table-view > label { font-size 24.px } tableView { tableColumn { label { fontSize = 32.px } } tableCell { fontSize = 24.px } tableRowCell { prefHeight = 60.px and(undergraduate) { backgroundColor += RED } and(graduate) { backgroundColor += GREEN } and(postgraduate) { backgroundColor += BLUE } } } } } fun main(args: Array) { launch(args) }