我正在用一个最简单的例子尝试scalafx,但它无法编译,错误如下:
Error:scalac: bad symbolic reference to javafx.stage.PopupWindow.AnchorLocation encountered in class file 'StageIncludes.class'. Cannot access type AnchorLocation in object javafx.stage.PopupWindow. The current classpath may be missing a definition for javafx.stage.PopupWindow.AnchorLocation, or StageIncludes.class may have been compiled against a version that's incompatible with the one found on the current classpath.
我用谷歌搜索,发现有人说我们需要将 jfxrt.jar
添加到类路径,但这仍然不起作用。
我的代码:
build.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
App.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
})
}
}
}
仅此而已。
最佳答案
这在 Java 8 JVM 上可以正常工作。可能的问题是您正在安装 Java 7。
通过这些release notes ScalaFX 有两个并行版本:
- v.1.0.0 - 支持 JavaFX 2 和 Java 7 (SFX-1)
- v.8.0.0 - 支持 JavaFX 8 和 Java 8 (SFX-8)
更新 Java,或使用其他版本。
关于scala - 一个最简单的scalafx例子无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23447259/