gpt4 book ai didi

java - 如何使用属性制作自定义事件?

转载 作者:行者123 更新时间:2023-12-02 02:28:56 24 4
gpt4 key购买 nike

如何制作自定义事件和自定义属性可以从 SceneBuilder/FXML 访问它吗? Should be available like this

该来源给出了答案,但只是部分答案 here

我需要类似的东西:

MyFragment.fxml

<SplitPane ......>
<fx:script>
function myFunction()
{
if(MyCustomControl.state){
id0.setText('1111111')
} else {
id0.setText('2222222')
}
}
</fx:script>
//How create this property?
<Label fx:id="id0" /> // |
// V
<MyCustomControl onMyCustomEvent="myFunction()"/>
</SplitPane>

最佳答案

对于 Kotlin:

val MY_CUSTOM_EVENT =
EventType<Event>(Event.ANY, "MY_CUSTOM_EVENT" + UUID.randomUUID().toString())
var onOnlineClick = object : SimpleObjectProperty<EventHandler<Event>>() {
override fun getBean(): Any {
return this
}

override fun getName(): String {
return "onMyCustomEvent"
}

override fun invalidated() {
setEventHandler(MY_CUSTOM_EVENT, get())
}
}

fun onMyCustomEvent(): ObjectPropertyBase<EventHandler<Event>> {
return onMyCustomEvent
}

fun setOnMyCustomEvent(value: EventHandler<Event>) {
onMyCustomEvent.set(value)
}

fun getOnMyCustomEvent(): EventHandler<Event> {
return onMyCustomEvent.get()
}

某处属性(property)

fun myProperty(): BooleanProperty {
return myCustomProperty ?: run {
myCustomProperty = object : SimpleBooleanProperty(false) {
override fun invalidated() {
fireEvent(Event(MY_CUSTOM_EVENT)) // <---this
}

override fun getBean(): Any {
return this
}

override fun getName(): String {
return "myProperty"
}
}
return myCustomProperty as SimpleBooleanProperty
}
}

关于java - 如何使用属性制作自定义事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57241055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com