简体   繁体   English

ScalaFX和FXML示例似乎不起作用

[英]ScalaFX and FXML example doesnt seem to work

I am following this example here 我在这里跟随这个例子

object DataEditor extends JFXApp {
  val resource = getClass.getResource("MainWindowView.FXML")
  if(resource == null){
    throw new IOException("Cannot load Resource")
  }
  val root:jfxs.Parent = jfxf.FXMLLoader.load(resource)

  stage = new PrimaryStage {
    title = "Data Editor"
    scene = new Scene(root)
  }
}

but for some reason new Scene(root) doesn't work as a constructor. 但是由于某种原因, new Scene(root)无法用作构造函数。

Root is meant to be javafx.scene and stage.scene is scalafx.scene.Scene so making root javafx.Parent doesn't work. 根应该是javafx.scene,stage.scene是scalafx.scene.Scene,因此使根javafx.Parent无效。

Have there been any changes to scalafx since these examples have been made?? 自制作这些示例以来,scalafx是否有任何更改?

The answer was because I stuck stuff in the middle of SFXML and normal scalaFX 答案是因为我将东西塞在SFXML和普通的scalaFX之间

First thing I found was import scalafx.Includes._ which is the one line I managed to ignore on the examples is a "magic line" that fixes all the weirdness between javaFX and scalaFX. 我发现的第一件事是import scalafx.Includes._ ,这是我在示例中忽略的那一行是“魔术线”,它修复了javaFX和scalaFX之间的所有怪异现象。 This fixes the No constructor errors for scene = new Scene(root) 这修复了scene = new Scene(root)No constructor错误

I had an @sfxml annotation on my controller class but wasn't loading it using SFXML's FXMLView which resulted in javafx failing to find a no args constructor. 我在控制器类上有一个@sfxml批注,但未使用SFXML的FXMLView加载它,这导致javafx找不到no args构造函数。

And finally FXMLView requires a Dependency resolver (Ie Subcut) but they also have a NoDependencyResolver object to save the bacon of us mortals who don't even need one yet FXMLView(resource, NoDependencyResolver) . 最后,FXMLView需要一个依赖项解析器(即Subcut),但它们还具有NoDependencyResolver对象,以保存我们甚至不需要FXMLView(resource, NoDependencyResolver)人类的培根。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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