TornadoFX 模态对话框不会自动调整高度
TornadoFX modal dialog isn't automatically adjusting height
我有一个打开模态对话框的 TornadoFX 应用程序。它有文本字段,如果输入无效会显示错误。
问题是模式对话框在显示或隐藏错误时不会自动调整其高度。
这是简化对话框在没有错误和有错误时的样子
这是一个简化的视图:
class InputView : View("Enter text") {
private val textProperty = SimpleStringProperty()
override val root: VBox = vbox {
label("Enter text below:")
textfield(textProperty)
label("Error message") {
visibleWhen(textProperty.isNotEmpty)
// This is necessary so that hidden error is really removed, see
managedProperty().bind(visibleProperty())
}
button("OK")
}
}
管理员点赞
inputView.openModal(owner = primaryStage)
TornadoFX和JavaFX有很多配置,比如prefHeight、usePrefHeight、fitToHeight、maxHeightProperty、vgrow。
我和他们一起玩过,但到目前为止运气不好。
有人可以指出使此对话框自动调整高度的正确方法吗?
在另一个 的帮助下,我找到了解决方案。
我不得不将以下内容添加到错误的节点:
visibleProperty().onChange {
currentWindow?.sizeToScene()
}
最终的简化代码看起来像
class InputView : View("Enter text") {
private val textProperty = SimpleStringProperty()
override val root: VBox = vbox {
label("Enter text below:")
textfield(textProperty)
label("Error message") {
visibleWhen(textProperty.isNotEmpty)
// This is necessary so that hidden error is really removed, see
managedProperty().bind(visibleProperty())
// This is necessary to automatically adjust dialog height when error is shown or hidden
visibleProperty().onChange {
currentWindow?.sizeToScene()
}
}
button("OK")
}
}
我有一个打开模态对话框的 TornadoFX 应用程序。它有文本字段,如果输入无效会显示错误。
问题是模式对话框在显示或隐藏错误时不会自动调整其高度。
这是简化对话框在没有错误和有错误时的样子
这是一个简化的视图:
class InputView : View("Enter text") {
private val textProperty = SimpleStringProperty()
override val root: VBox = vbox {
label("Enter text below:")
textfield(textProperty)
label("Error message") {
visibleWhen(textProperty.isNotEmpty)
// This is necessary so that hidden error is really removed, see
managedProperty().bind(visibleProperty())
}
button("OK")
}
}
管理员点赞
inputView.openModal(owner = primaryStage)
TornadoFX和JavaFX有很多配置,比如prefHeight、usePrefHeight、fitToHeight、maxHeightProperty、vgrow。 我和他们一起玩过,但到目前为止运气不好。
有人可以指出使此对话框自动调整高度的正确方法吗?
在另一个
visibleProperty().onChange {
currentWindow?.sizeToScene()
}
最终的简化代码看起来像
class InputView : View("Enter text") {
private val textProperty = SimpleStringProperty()
override val root: VBox = vbox {
label("Enter text below:")
textfield(textProperty)
label("Error message") {
visibleWhen(textProperty.isNotEmpty)
// This is necessary so that hidden error is really removed, see
managedProperty().bind(visibleProperty())
// This is necessary to automatically adjust dialog height when error is shown or hidden
visibleProperty().onChange {
currentWindow?.sizeToScene()
}
}
button("OK")
}
}