Image class and paths relative to classpath
Martin Sladecek
martin.sladecek at oracle.com
Mon Apr 23 23:14:25 PDT 2012
I checked FXML and both relative and absolute paths work well when using
"@" prefix, so I don't see a problem here. I have to check CSS.
-Martin
On 04/23/2012 06:12 PM, Kevin Rushforth wrote:
> Whatever we do, it should be the compatible with what is done for FXML
> and CSS, both of which have to face the same issue.
>
> -- Kevin
>
>
> Daniel Zwolenski wrote:
>> An alternative to the separate method is to define a 'classpath'
>> protocol as part of the URL:
>>
>> Image image = new Image("classpath:/foo/bar.png");
>> This is common in Spring and seems quite nice to me. It has the
>> advantage of working with constructors and is fully backwards
>> compatible.
>> I could live with a new method if that was the preference though.
>>
>> On 23/04/2012, at 10:58 PM, Martin Sladecek
>> <martin.sladecek at oracle.com> wrote:
>>
>>> Hello,
>>>
>>> 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 present.
>>> 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
>>> backgroundLoading);
>>>
>>> + 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?
>>>
>>> -Martin
More information about the openjfx-dev
mailing list