Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
    }
  }
}
like image 253
ideaboxer Avatar asked Mar 15 '16 22:03

ideaboxer


1 Answers

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

like image 101
Eugene Ryzhikov Avatar answered Nov 12 '22 18:11

Eugene Ryzhikov