我正在用一个最简单的例子尝试scalafx,但它无法编译,错误如下:
错误:scalac:在类文件“StageIncludes.class”中遇到对 javafx.stage.PopupWindow.AnchorLocation 的错误符号引用。无法访问对象 javafx.stage.PopupWindow 中的类型 AnchorLocation。当前类路径可能缺少 javafx.stage.PopupWindow.AnchorLocation 的定义,或者 StageIncludes.class 可能已针对与当前类路径中找到的版本不兼容的版本进行编译。
我用谷歌搜索,发现有人说我们需要添加jfxrt.jar
到类路径,但这仍然不起作用。
我的代码:
构建.sbt
name := "ColaBlog"
version := "0.1.0"
scalaVersion := "2.11.0"
libraryDependencies ++= List(
"org.scalafx" % "scalafx_2.11" % "8.0.0-R4"
)
unmanagedJars in Compile += Attributed.blank(
file(scala.util.Properties.javaHome) / "lib" / "jfxrt.jar")
fork in run := true
应用程序.scala
import scalafx.Includes._
import scalafx.application.JFXApp
import scalafx.scene.Scene
import scalafx.scene.paint.Color
import scalafx.scene.shape.Rectangle
object App extends JFXApp {
stage = new JFXApp.PrimaryStage {
title = "Hello World"
width = 600
height = 450
scene = new Scene {
fill = Color.LIGHTGREEN
content = Set(new Rectangle {
x = 25
y = 40
width = 100
height = 100
fill <== when(hover) choose Color.GREEN otherwise Color.RED
})
}
}
}
就这样。