[英]ScalaFX (JavaFX): Stage content does not resize on window resize
To inspect this unexpected behavior, I simply put a TextArea
directly into the Scene
contained by the PrimaryStage
: On app start, the TextArea
exactly fits the window (as expected). 要检查这种意外行为,我只需将
TextArea
直接放入PrimaryStage
包含的Scene
中:在应用程序启动时, TextArea
完全适合窗口(如预期的那样)。
But the size of the TextArea
does not change if I move the window's borders, which is the problem I am trying to solve. 但是如果我移动窗口的边框,
TextArea
的大小不会改变,这是我试图解决的问题。
Please see my Screenshot 请看我的截图
This is my ScalaFX code (which I expect to act exactly like its JavaFX equivalent): 这是我的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
}
}
}
For TextArea
to resize properly you need a layout. 要使
TextArea
正确调整大小,您需要一个布局。 For example BorderPane
should be used as scene's content
. 例如,
BorderPane
应该用作场景的content
。
More about layouts can found at http://docs.oracle.com/javase/8/javafx/layout-tutorial/builtin_layouts.htm#JFXLY102 有关布局的更多信息,请访问http://docs.oracle.com/javase/8/javafx/layout-tutorial/builtin_layouts.htm#JFXLY102
UPDATE
UPDATE
After looking at the ScalaFX source code,I realized that
root
should be used instead ofcontent
on the scene在查看ScalaFX源代码后,我意识到应该使用
root
而不是场景中的content
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.