1

Does anyone know where in an sbt directory structure ScalaFX looks for CSS style sheets? I've tried putting them in the same directory as my ScalaFX app main file, in a resources directory, directly in src, and pretty much everywhere else - yet every time I get a message saying Resource "whatever path I'm using/style.css" not found.

hegash
  • 833
  • 1
  • 7
  • 16
  • 1
    The CSS files are loaded at runtime, so the rules are going to be exactly the same as for Java. See https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other – James_D Aug 14 '22 at 18:21

1 Answers1

2

In SBT project you put CSS stylesheets in src/main/resources

You can see an example project using CSS here https://github.com/scalafx/scalafx-ensemble

Assuming that your stylesheet is in src/main/resources/path/my.css you can load it like this

scene = new Scene {
  stylesheets += this.getClass.getResource("/path/my.css").toExternalForm
  ...
}
Jarek
  • 1,513
  • 9
  • 16