ScalaFX (JavaFX):舞台内容不会在 window 调整大小时调整大小

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

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

但是如果我移动window的边框,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