我在这里关注这个例子
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) } }但由于某种原因, new Scene(root)不能用作构造函数。
Root应该是javafx.scene而stage.scene是scalafx.scene.Scene所以使root javafx.Parent不起作用。
scalafx是否有任何变化,因为这些例子已经制作完成?
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.
Root is meant to be javafx.scene and stage.scene is scalafx.scene.Scene so making root javafx.Parent doesn't work.
Have there been any changes to scalafx since these examples have been made??
最满意答案
答案是因为我把东西放在了SFXML和普通scalaFX的中间
我发现的第一件事是import scalafx.Includes._这是我在示例中设法忽略的一行是一条“魔术线”,它修复了javaFX和scalaFX之间的所有奇怪现象。 这修复了scene = new Scene(root)的No constructor错误
我在我的控制器类上有一个@sfxml注释,但是没有使用SFXML的FXMLView加载它,这导致javafx无法找到no args构造函数。
最后FXMLView需要一个Dependency解析器(即Subcut),但他们还有一个NoDependencyResolver对象来保存我们凡人的培根,他们甚至不需要一个FXMLView(resource, NoDependencyResolver) 。
The answer was because I stuck stuff in the middle of SFXML and normal 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. This fixes the No constructor errors for scene = new Scene(root)
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.
And finally FXMLView requires a Dependency resolver (I.e. 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).
更多推荐
发布评论