Well, this took me awhile. But it was a pain not being able to load images from within my CSS file. The problem lies because the absolute path is different when you test it compared with the result when deployed.

Let us say this is how I want my button to look like:

When you run it in your local development environment, you wonder why the image would not load. Try to call this within your code

and you will see why. In my case, the result was something like E:/folder/build/classes/images/bullet_black.png

Now, for it to work if you call it from within the CSS file, you would have to do it like this:

The problem then is when you deploy it, there is no drive E from inside the JAR file. So what is the solution then?

Do it programmatically. This is how I did it within my Button class

If only we could use the @- keyword to make it look like this:

But we cannot as it is a Java FX limitation and this keyword is ignored.

Related Posts Plugin for WordPress, Blogger...