繁体   English   中英

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

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

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

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

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

UPDATE

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM