Home > database >  Getting an error that I cannot resolve symbol scalafx
Getting an error that I cannot resolve symbol scalafx

Time:07-09

Beginner at scala here, been trying to import scalafx into my scala file but I just can't seem to do so.

import scalafx.application.JFXApp

object Main extends JFXApp{

}

And the sbt file that I have is

ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "2.13.8"

lazy val root = (project in file("."))
  .settings(
    name := "SnakeFX"
  )
libraryDependencies  = "org.scalafx" %% "scalafx" % "16.0.0-R24"

Any fix for this?

CodePudding user response:

To use ScalaFX you need to add a dependency on the ScalaFX library and also corresponding version of the JavaFX. JavaFX binaries are system dependent.

You need to tell sbt about the OS you are running, using something like:

libraryDependencies   = {
  // Determine OS version of JavaFX binaries
  lazy val osName = System.getProperty("os.name") match {
    case n if n.startsWith("Linux") => "linux"
    case n if n.startsWith("Mac") => "mac"
    case n if n.startsWith("Windows") => "win"
    case _ => throw new Exception("Unknown platform!")
  }
  Seq("base", "controls", "fxml", "graphics", "media", "swing", "web")
    .map(m => "org.openjfx" % s"javafx-$m" % "16" classifier osName)
}

You can read the entire ScalaFX tutorial enter image description here

After loading them, you should be ready to work with ScalaFX. Happy coding!

  • Related