gpt4 book ai didi

java - ScalaFX (JavaFX) : Stage content does not resize on window resize

转载 作者:搜寻专家 更新时间:2023-11-01 03:19:14 28 4
gpt4 key购买 nike

为了检查这种意外行为,我只是将 TextArea 直接放入 PrimaryStage 包含的 Scene 中:在应用程序启动时,TextArea 完全适合窗口(正如预期的那样)。

但是如果我移动窗口的边框,TextArea 的大小不会改变,这就是我要解决的问题。

Please see my Screenshot

这是我的 ScalaFX 代码(我希望它的行为与它的 JavaFX 等价物完全一样):

object MyApp extends JFXApp {
stage = new PrimaryStage {
title = "My App"
resizable = true // has no effect
maxWidth = Double.MaxValue // has no effect
maxHeight = Double.MaxValue // has no effect

val outputDisplay = new TextArea {
resizable = true // has no effect
maxWidth = Double.MaxValue // has no effect
maxHeight = Double.MaxValue // has no effect
hgrow = Priority.Always // has no effect
vgrow = Priority.Always // has no effect
}

scene = new Scene {
resizable = true // has no effect
maxWidth = Double.MaxValue // has no effect
maxHeight = Double.MaxValue // has no effect
fill = LightGreen

// add outputDisplay as content
content = outputDisplay
}
}
}

最佳答案

要使 TextArea 正确调整大小,您需要一个布局。例如 BorderPane 应该用作场景的 content

有关布局的更多信息,请访问 http://docs.oracle.com/javase/8/javafx/layout-tutorial/builtin_layouts.htm#JFXLY102

UPDATE

After looking at the ScalaFX source code,I realized that root should be used instead of content on the scene

关于java - ScalaFX (JavaFX) : Stage content does not resize on window resize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36023189/

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