简体   繁体   中英

How to interact with an FXML form in ScalaFx?

Considering this example how do I get or set anything on the form from the Main code?

All we have is a simple Main object like

object Main extends JFXApp {

  val resource = getClass.getResource("/AdoptionForm.fxml")

  val root: jfxs.Parent = jfxf.FXMLLoader.load(resource)

  stage = new PrimaryStage() {
    title = "FXML GridPane Demo"
    scene = new Scene(root)
  }

}

A form defined in FXML.

And a controller class which is never instantiated explicitly.

As far as the controller is a class (not an object) and I don't have a link to its instance in the Main code, how do I access anything on the form?

The final goal I seek to reach is to have an actor that would listen to incoming messages and update the form with the data gotten.

You can get the Controller from the FXML loader.

val loader = new jfxf.FXMLLoader(resource)
val root = loader.load[jfxs.Parent]
val controller = loader.getController[Controller]

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