java - TornadoFX 模态对话框不会自动调整高度
问题描述
我有一个 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 https://stackoverflow.com/a/28559958/519035
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 https://stackoverflow.com/a/28559958/519035
managedProperty().bind(visibleProperty())
// This is necessary to automatically adjust dialog height when error is shown or hidden
visibleProperty().onChange {
currentWindow?.sizeToScene()
}
}
button("OK")
}
}
推荐阅读
- google-chrome - Chrome 扩展,无法显示工具栏中的图标
- swagger - 如何让 Quarkus Swagger 识别 JsonSerialize(as=)、JsonDeserialize(as=)
- python - 来自包含空字符的字节数组的 PyByteArray_AsString 的解决方法
- python - 为什么我的 taylor 系列在函数中添加了 x?
- css - 更改活动/单击的背景颜色 react-bootstrap 按钮
- android - 尝试使用外国 RGB 显示器进行编程时从哪里开始?
- visual-studio - VS2019 显示更新通知,但 VSIX 扩展安装程序显示已安装更新
- jquery - 如何使用 AJAX 将 JSON 发送到 Django URL?
- vue.js - 无法让 twitter Oauth 身份验证与 nuxt-auth 一起使用
- javascript - 如何使用 Python Selenium 通过 aria-label 查找并单击 JavaScript 按钮?