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

ide*_*xer 5 java scala javafx scalafx

检查这种意外的行为,我只是把一个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
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Eug*_*kov 4

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

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

更新

查看ScalaFX源代码后,我意识到root应该使用而不是content在场景中