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

1 回答 1

0

在 JavaFX 中,创建Sceneone 时必须指定根节点,即Parent. ScalaFX 提供了一个默认的承包商来Scene指定Group为根节点。在 ScalaFXScene#content中是访问根节点子节点的快捷方式,默认情况下这些子节点是Group.

在您的情况下,由于的调整大小行为,您不希望将 aGroup作为根节点。Group

你场景的根节点应该是你的BorderPane,所以将它分配给root而不是content

scene = new Scene {
  root = new BorderPane { ...
  }
}
于 2016-01-06T04:21:33.293 回答