ScalaFX和FXML示例似乎不起作用(ScalaFX and FXML example doesnt seem to work)

编程入门 行业动态 更新时间:2024-10-19 08:45:30
ScalaFX和FXML示例似乎不起作用(ScalaFX and FXML example doesnt seem to work)

我在这里关注这个例子

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).

更多推荐

本文发布于:2023-07-04 17:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026989.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:示例   不起作用   FXML   ScalaFX   doesnt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!