Reputation: 275
I am creating a scalafx application and I cannot get it to communicate with an external stylesheet. I get a NullPointerException if I use
getClass.getResource
and if I do
stylesheets = "styles.css"
I get a message from sbt saying it cannot find my stylesheet. 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 ->
main ->
scala, resources ->
Both files are in 'scala' directory.
Any help is greatly appreciated.
Upvotes: 1
Views: 1270
Reputation: 1533
"styles.css" needs to be in the resources
under sub-directory corresponding to package where Main
class is.
Upvotes: 2