Classpath-relative URLs in CSS

Werner Lehmann lehmann at
Thu May 31 10:42:05 PDT 2012


last month I learned that FXML can process absolute paths (relative to
the root of the classpath, see quoted portion below). It would be nice 
to have the same in css as well:

> -fx-background-image: url("/some/source/folder/arrow.png");

Currently I have to do this instead:

> -fx-background-image: url("../../../arrow.png");

And when the css file is moved to a different package I have to remember
to update the relative urls. Also, it does not seem to work with
resources inherited from a dependency project (might be an Eclipse issue
but I suppose it would work if the class loader was used).

The css reference says:

> "/com/wicked/cool/resources/styles.css" is treated as
> "com/wicked/cool/resources/styles.css". This is consistent with FXML.

It seems logical to support this not only for the stylesheet but also 
for urls in the stylesheet, just like urls in FXML...


On 23.04.2012 18:40, Greg Brown wrote:
>> Correct me if I am wrong but today FXML seems to support relative
>> paths only. For instance, if I have a shared image resource
>> "warning.png" in the root of the classpath, I have to specify it
>> like "../../../../warning.png" in the FXML, depending on which
>> package the FXML is in.
> Currently, you can specify either a relative path (e.g.
> "../../warning.png") or an absolute path (relative to the classpath;
> e.g. "/warning.png") in FXML. This works for includes, script files,
> and attributes with a leading "@" symbol.
> G

More information about the openjfx-dev mailing list