最简单的scalafx示例无法编译 [英] A simplest scalafx example can't be compiled

查看:78
本文介绍了最简单的scalafx示例无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最简单的示例尝试scalafx,但无法编译,并且错误如下:

I'm trying the scalafx with a simplest example, but it can't be compiled and the error is like:

错误:scalac:对类文件'StageIncludes.class'中遇到的javafx.stage.PopupWindow.AnchorLocation的错误符号引用. 无法访问对象javafx.stage.PopupWindow中的类型AnchorLocation.当前的类路径可能是 缺少javafx.stage.PopupWindow.AnchorLocation的定义,或StageIncludes.class可能已经针对以下版本进行了编译: 与当前类路径中找到的不兼容.

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.

我在Google上搜索,发现有人说我们需要将jfxrt.jar添加到类路径中,但是仍然无法正常工作.

I googled and found someone say we need to add the jfxrt.jar to classpath, but which is still not working.

我的代码:

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安装.

This works correctly on the Java 8 JVM. The likely problem is that you are running on a Java 7 install.

通过这些发行说明 ScalaFX具有两个并行发行版:

By these release notes ScalaFX has two parallel releases:

  • v.1.0.0-支持JavaFX 2和Java 7(SFX-1)
  • v.8.0.0-支持JavaFX 8和Java 8(SFX-8)

要么更新Java,要么使用另一个版本.

Either update Java, or use the other release.

这篇关于最简单的scalafx示例无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆