I'm trying the scalafx with a simplest example, but it can't be compiled and the error is like:
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.
I googled and found someone say we need to add the jfxrt.jar
to classpath, but which is still not working.
My code:
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
})
}
}
}
That's all.