简体   繁体   中英

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

To inspect this unexpected behavior, I simply put a TextArea directly into the Scene contained by the PrimaryStage : On app start, the TextArea exactly fits the window (as expected).

But the size of the TextArea does not change if I move the window's borders, which is the problem I am trying to solve.

Please see my Screenshot

This is my ScalaFX code (which I expect to act exactly like its JavaFX equivalent):

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
    }
  }
}

For TextArea to resize properly you need a layout. For example BorderPane should be used as scene's content .

More about layouts can found at 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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