gpt4 book ai didi

user-interface - 如何删除在borderpane上添加的Fragment()?

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

我有一个带toggleButton的边框。并根据其下面的toggleButton的状态,我需要具有ClientForm:Fragment()或ServerForm:Fragment()。添加这些Fragment()后如何删除?

override val root = borderpane {
top {
setPrefSize(250.0, 100.0)
paddingAll = 10.0
useMaxHeight = true
useMaxWidth = true
togglebutton("Выбрать режим клиента") {
useMaxWidth = true
action {
text = if (isSelected) "Выбрать режим сервера" else "Выбрать режим клиента"
if (isSelected) {
// REMOVE ServerForm: Fragment from borderpane.center
// ADD ClientForm: Fragment() to borderpane.center
} else {
// REMOVE ClientForm: Fragment from borderpane.center
// ADD ServerForm: Fragment() to borderpane.center
}
}
}
}
center {
add(find(ServerForm::class))
}
}

这些片段:
class ClientForm: Fragment() {
override val root = form {
fieldset(labelPosition = Orientation.VERTICAL) {
fieldset("IP") {
textfield(ip).required()
}
fieldset("PORT") {
textfield(port).required()
}
button("Connect") {
}
}
label() {
}
}
}

class ServerForm: Fragment() {
override val root = form {
fieldset(labelPosition = Orientation.VERTICAL) {
fieldset("PORT") {
textfield(port).required()
}
button("Start server") {

}
}
label()
}
}

最佳答案

removeWhen()扩展功能,需要ObservableValue<Boolean>
用途如下:

label(" Display flag is false ") {
removeWhen(displayFlag)
}
label(" Display flag is true") {
removeWhen(!displayFlag)
}

还有 visibleWhen()hiddenWhen()扩展功能,以防您只需要隐藏片段。

关于user-interface - 如何删除在borderpane上添加的Fragment()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61888448/

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