Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to set the path of a BackgroundImage in JavaFX CSS

I have an AnchorPane and I want to style it by giving it a BackgroundImage I have in another package : File Structure Screenshot

Here's the CSS I tried:

#body 
{
    -fx-background-image:url("/Images/FlowersPattern_beige_background.jpg");   
}

Using javascript I set the AnchorPane's CSS id to body; that didn't work. I tried to check other questions already asked, but they didn't help. Please can you clarify how, exactly, it should be done?

like image 201
AymenDaoudi Avatar asked Mar 23 '23 22:03

AymenDaoudi


1 Answers

If your css file is loaded normally, Replacing:

"/Images/FlowersPattern_beige_background.jpg"

with

"../Images/FlowersPattern_beige_background.jpg"

should work.

The path is relative to the css file's directory, the .. accesses the parent directory (src); /Images refers to the Images directory; finally /FlowersPattern_beige_background.jpg accesses your image.

like image 92
Salah Eddine Taouririt Avatar answered Apr 07 '23 08:04

Salah Eddine Taouririt