我有一个ScalaFX应用程序,我正在使用FXML来查看我的视图。我很难将视图连接到控制器。我在网上找不到很多信息,除了Github上的例子,即使我试图模仿它们是如何做的,它也不起作用。以下是我在FXML中连接它的方法。
imports...
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="520.0" minWidth="880.0" prefHeight="520.0"
prefWidth="880.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="scala/scalafxml/ToolbarController">
<center....
这是我的控制器类......
@sfxml
class ToolbarController extends JFXApp {
//open new form
def newForm = {
val resource = getClass.getResource("/scala/scalafxml/form.fxml")
堆栈跟踪说它特别找不到fx:controller引用的控制器类。在这里。
Exception in Application start method
Workaround until RT-13281 is implemented: keep toolkit alive
[error] (run-main-0) java.lang.RuntimeException: Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
at com.sun.javafx.application.LauncherImpl$$Lambda$9/777613804.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
/Users/patrickslagle/scala/MyApps/PattyCakesWorksheet/target/scala-2.10/classes/scalafxml/calendar.fxml:9
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:918)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2711)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2531)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
at FXMLMain$delayedInit$body.apply(FXMLMain.scala:16)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
at scalafx.application.JFXApp$class.init(JFXApp.scala:297)
at FXMLMain$.init(FXMLMain.scala:10)
at scalafx.application.AppHelper.start(AppHelper.scala:33)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$60/206252937.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$56/1146564181.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$58/354390534.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$57/1198063642.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.ClassNotFoundException: scala/scalafxml/ToolbarController
at java.lang.ClassLoader.findClass(ClassLoader.java:530)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 11 s, completed May 24, 2016 3:32:56 PM
FXML文件位于src / main / resources / scalafxml / calendar.fxml,控制器位于src / main / scala / scalafxml / ToolbarController.scala。
我可能有一些明显错误,因为我在Scala非常环保。任何指针都非常感谢。
答案 0 :(得分:2)
看一下这个独立的例子: https://github.com/vigoo/scalafxml-unit-converter-example
您应该有一个单独的控制器类和@-webkit-keyframes autofill {
to {
color: #666;
background: transparent;
}
}
input:-webkit-autofill {
-webkit-animation-name: autofill;
-webkit-animation-fill-mode: both;
}
,并使用ScalaFXML中的JFXApp
构造函数来创建视图。