要检查这种意外行为,我只需将TextArea
直接放入Scene
所包含的PrimaryStage
:在应用开始时,TextArea
完全适合窗口(如预期的那样。)
但如果我移动窗口的边框,TextArea
的大小不会改变,这是我要解决的问题。
这是我的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
}
}
}
答案 0 :(得分:2)
要让TextArea
正确调整大小,您需要一个布局。例如,BorderPane
应该用作场景content
。
有关布局的更多信息,请参见http://docs.oracle.com/javase/8/javafx/layout-tutorial/builtin_layouts.htm#JFXLY102
更新
在查看ScalaFX源代码后,我意识到应该在场景中使用
root
而不是content