0

I have been trying to convert a school project I originally written in Java with Swing to Scala with ScalaFX. The GUI is basically a top bar with Buttons and a search input, while the bottom part of the bar is a TextArea that will display the output from the buttons. This is what the app looks like at startup. The problem is that when I expand the stage with my mouse, the size of the TextArea remains static. Here is an example of that. I tried looking up specific help for ScalaFX but it feels like the documentation out there is rather thin, so I have had to focus my research for JavaFX. I found a post on here about using HBox to have my textbox expand as I stretch the stage with my mouse, but it doesn't appear to be working. Is there a way to have the TextArea scale in size when the stage is stretched out with the mouse? I have included the code below of the GUI with the added HBox below.

object SorcerersCave extends JFXApp{
  val informationText: TextArea = new TextArea()

  stage = new PrimaryStage {
      title = "Sorcerers Cave"
      val searchBy = new ComboBox[String](List("Index", "Name", "Type")){
        value = "Index"
      }
      val resizeableBox = new HBox(informationText){
        hgrow = Priority.Always
      }
      val searchInput = new TextField() {prefWidth = 100}
      val buttonPane = new FlowPane {
        hgap = 5
        children = Seq(new Button("Read") { onAction = handle { readFile }} ,
                       new Button("Display"){ onAction = handle { displayCave() }},
                       searchBy,
                       new Label("Search target:"),
                       searchInput,
                       new Button("Search"){ onAction = handle { search(searchInput.getText.toLowerCase.trim, searchBy.toString()) }}
        )
      }
      scene = new Scene {
        content = new BorderPane {
             top = buttonPane
             center = resizeableBox
        }
      }
  }
}

1 Answers1

0

In JavaFX, when creating a Scene one must specify the root node that is a Parent. ScalaFX provides a default contractor for Scene assigning Group as the root node. In ScalaFX Scene#content is a shortcut accessing children of the root node, by default those are children of a Group.

In your case you do not want to have a Group as a root node due to Group's re-sizing behavior.

You scene's root node should be your BorderPane, so assign it to root rather than to content:

scene = new Scene {
  root = new BorderPane { ...
  }
}
Jarek
  • 1,513
  • 9
  • 16