tornadofx使用slider、spinner控件

本文介绍了一个使用 JavaFX 创建的简单用户界面示例,包括 Spinner 和 Slider 控件的使用,展示了如何通过属性绑定和监听器来实现 UI 的动态更新。


import javafx.application.Application
import javafx.geometry.Pos
import tornadofx.*

fun main() = Application.launch(TestApp::class.java)
class TestApp : App(TestView::class)
class TestView : View("Learn") {
    val maxDepth = intProperty(1)
    val sliderr = intProperty(1)
    val oldValuee = intProperty(0)

    override val root = vbox(10) {
        prefHeight = 200.0
        prefWidth = 250.0
        alignment = Pos.CENTER
        label(maxDepth.stringBinding{"spinner, oldValue: ${oldValuee.value}, newValue: ${maxDepth.value}"})
        spinner(1, 10, 4, 1, true, maxDepth) {
            minWidth = 200.0
            valueProperty().addListener { _, oldValue, newValue ->
                oldValuee.value=oldValue.toInt()

            }
        }

        label(sliderr.stringBinding { "slider value: $it" })
        slider(1,10,4){
            maxWidth = 150.0
            isShowTickLabels = true
            isShowTickMarks = true
            valueProperty().bindBidirectional(sliderr)
            valueProperty().addListener { _, oldValue, newValue ->
                println("oldValue: ${oldValue.toInt()}, newValue: ${newValue.toInt()}")
            }
        }
    }
}

 

转载于:https://my.oschina.net/u/3820046/blog/3096738

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值