scalaFX样式表悄然失败

时间:2016-06-13 18:28:27

标签: javafx-8 scalafx

我正在学习scalaFX / javaFX经过多年的摇摆和scalaSwing的几个月。 ScalaSwing有一些我觉得不值得处理的小问题,因为有机会更新到当前的东西。我遇到问题并不让我感到惊讶,但我很担心。

这是我正在做的事情的问题吗?我需要黑色背景,这似乎是失败的,并没有告诉我为什么。

如果我先添加按钮然后再添加一个矩形,我可以解决这个问题。我试过包装矩形,但这不是解决方案。

谢谢!

object Broken extends JFXApp {

  stage = new PrimaryStage {
    x = 0
    y = 0
    scene = new Scene {
      stylesheets add getClass.getResource("Dark.css").toExternalForm
      root = new FlowPane {
        padding = Insets(10)
        children = List(new Rectangle() {
          x = 0
          y = 0
          width = 100
          height = 150
          arcHeight = 20
          arcWidth = 20
          fill = Color.Red
        })
      }
    }
  }
}


object Works extends JFXApp {

  stage = new PrimaryStage {
    x = 0
    y = 0
    scene = new Scene {
      stylesheets add getClass.getResource("Dark.css").toExternalForm
      root = new FlowPane {
        padding = Insets(10)
        children = List(new Button("Works"))
      }
    }
  }
}

将此作为Dark.css(文件)放在同一个包中

 //Dark.css
.root{
    -fx-font-size: 14pt;
    -fx-font-family: "Courier New";
    -fx-base: rgb(25,25,65);
    -fx-background: rgb(0, 0, 0);
}

0 个答案:

没有答案