簡體   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