前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >javafx框架tornadofx入门30_类型安全的样式-使用样式类

javafx框架tornadofx入门30_类型安全的样式-使用样式类

原创
作者头像
用户6167008
修改2020-05-07 18:02:16
7300
修改2020-05-07 18:02:16
举报
class MyStyle : Stylesheet() {
    companion object {
        val leftBox by cssclass()// View中通过 addClass(MyStyle.leftBox) 使用此样式
        val labelOne by cssid()// View中id为"label-one"的控件使用此样式
        val two by cssclass()// View中通过 addClass(MyStyle.two) 使用此样式
    }

    init {
        leftBox {
            borderColor += box(Color.ORANGE)
            padding = box(5.px)
            button {
                backgroundColor += Color.RED
                and(hover) {//  鼠标停留在该控件上时宽度变为200px,背景色变为蓝色
                    prefWidth = 200.px
                    backgroundColor += Color.BLUE
                }
            }
            label{
                backgroundColor += Color.YELLOW
                backgroundInsets += box(2.px)
                and(hover) {//  鼠标停留在该控件上时高度变为100px
                    prefHeight = 100.px
                }
            }
        }
        cell {// listview或tabelview等包含单元格的控件,当选中的单元格的背景色为红色
            and(selected) {
                backgroundColor += Color.RED
            }
        }
        s(button, label) {// 统一设置button、label的字体大小
            fontSize = 20.px
        }
        button{// 应用该样式类的view中所有button控件的字体颜色都为白色
            textFill = Color.WHITE
        }
        label{// 应用该样式类的view中所有label控件的字体颜色都为红色
            textFill = Color.RED
        }
        labelOne{// View中id为"label-one"的控件使用此样式
            backgroundColor += Color.AZURE
        }
        two{// View中通过 addClass(MyStyle.two) 使用此样式
            backgroundColor += Color.BLUE
        }
    }
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档