简体   繁体   English

Scalafx和CSS样式表

[英]Scalafx and CSS Stylesheets

I am creating a scalafx application and I cannot get it to communicate with an external stylesheet. 我正在创建一个scalafx应用程序,但无法使其与外部样式表进行通信。 I get a NullPointerException if I use 如果使用,则会收到NullPointerException

getClass.getResource getClass.getResource

and if I do 如果我愿意

stylesheets = "styles.css" stylesheets =“ styles.css”

I get a message from sbt saying it cannot find my stylesheet. 我从sbt收到一条消息,说它找不到我的样式表。 I have scoured the internet and tried to mimic what other projects have done but still have this same problem. 我搜寻了互联网并试图模仿其他项目所做的事情,但仍然存在相同的问题。 Here is a portion of my code where I add the stylesheet. 这是我的代码的一部分,在其中添加了样式表。 Both files are in the same directory. 这两个文件都在同一目录中。

object Main extends JFXApp with toolbarComponent with menubarComponent {
  stage = new JFXApp.PrimaryStage {
    scene = new Scene(880, 520) {
      stylesheets = List(getClass.getResource("styles.css").toExternalForm)
...
}

My directory structure goes like this: 我的目录结构如下:

[Directory File] -> [目录文件]->

src -> src->

main -> 主要->

scala, resources -> 斯卡拉,资源->

Both files are in 'scala' directory. 这两个文件都在“ scala”目录中。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

“ styles.css”必须位于与Main类所在的包相对应的子目录下的resources中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM