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

时间:2016-03-15 22:09:02

标签: java scala javafx scalafx

要检查这种意外行为,我只需将TextArea直接放入Scene所包含的PrimaryStage:在应用开始时,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
    }
  }
}

1 个答案:

答案 0 :(得分:2)

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

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

  

更新

     

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