6

I am trying to add background image to some pane in my javafx application, the image is located inside the package resources.img and the css is located inside the package resources.css

if i setting the background image programmatically like suggested in this thread: Setting background image by javafx code (not css)

it works fine but i would like to know if i can set the background image from the css file itself.

i tried

-fx-background-image: url("@../img/myImage.png");

but then the css interpreter didn't find the image file. is it possible to do what i want via css?

Community
  • 1
  • 1
bennyl
  • 2,886
  • 2
  • 29
  • 43

2 Answers2

4

JavaFX CSS parser has a limitation like

@-keyword statements are ignored.

described in "Limitations" section of CSS Reference Guide. It may be the cause of your problem though didn't confirm myself. Can you try like this: -fx-background-image: url("../img/myImage.png");
or -fx-background-image: url("resources/img/myImage.png");.

Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
0

Perhaps someone it will be useful. If you specified: -fx-background-image: url("resources/img/myImage.png");. It's possible that standalone .jar file will successfully load the image while IDE(like Eclipse) won't. It because IDE alters path and will search something like: C:/My_project/resources/css/resources/img/myImage.png. It means root for specified path will folder with css file instead of .jar package

Lurking Elk
  • 163
  • 1
  • 4