Image class and paths relative to classpath
lehmann at media-interactive.de
Mon Apr 23 09:18:28 PDT 2012
I have to admit that I did not really understand Richards two different
notions of "relative paths" in RT-18291.
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.
For shared resources (which are not local to the FXML) I'd like to be
able to use "/warning.png" as absolute path. That would also work after
moving the FXML to a different package.
So, if that or a similar way would become possible in FXML, I am all for it.
On 23.04.2012 16:58, Martin Sladecek wrote:
> JIRA: http://javafx-jira.kenai.com/browse/RT-18291
> this JIRA request is about adding support for "URL" in Image constructor
> that is interpreted as a classpath-relative path when a leading slash is
> However, this is currently interpreted as absolute file URL.
> In order not to break current behaviour I propose to introduce new set
> of static factory methods.
> Image.fromClassPath(String path, double requestedWidth, double
> requestedHeight, boolean preserveRatio, boolean smooth, boolean
> + overloaded method similar to Image constructors.
> The idea is to interpret paths with leading slash as absolute to the
> classpath root (basically the same as
> Thread.currentThread().getContextClassLoader().getResource(path) ),
> while relative paths might be interpreted as relative to the caller
> class. So Image.fromClassPath("duke.jpg") called from
> myapplication.Application will look for the file in myapplication package.
> What do you think?
More information about the openjfx-dev