如何删除 borderpane 上添加的 Fragment ()?
How to remove added Fragment () on borderpane?
我有一个带切换按钮的边框。并且根据它下面的 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()
扩展函数,以防您只需要隐藏片段。
我有一个带切换按钮的边框。并且根据它下面的 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()
扩展函数,以防您只需要隐藏片段。