JI-9056801 : Scene: Allow to add a stylesheet using a typed URL, not a stringified URL
nlisker at gmail.com
Sun Sep 16 13:01:33 UTC 2018
I think this needs to be discussed with a project lead - Kevin or Johan.
On Sun, Sep 16, 2018 at 6:07 AM Michael Binz <michab66 at gmail.com> wrote:
> Hi Nir,
> I understand that switching the API to use net.URL is not trivial.
> The only idea that comes to mind is to offer two list properties, the one
> existing as today, holding stringified URLs for backwards compatibility,
> and a second one that holds typed .net.URLs. The existing version can be
> deprecated in favour of the typed version.
> Before starting such an effort it would be interesting if it is common
> understanding that an URL instance is preferrable over a string URL.
> Was there a special reason that JavaFX uses in its interfaces in many
> places stringified URLs instead of the existing java.net.URL?
> Best wishes,
> Am Fr., 14. Sep. 2018 um 14:23 Uhr schrieb Nir Lisker <nlisker at gmail.com>:
>> Hi Michael,
>> The issue in the JBS is JDK-8209921 .
>> getStylesheets() returns an ObservableList<String>, it cannot be changed
>> to ObservableList<URL>. What solution do you propose?
>>  https://bugs.openjdk.java.net/browse/JDK-8209921
>> - Nir
>> On Wed, Aug 22, 2018 at 9:47 PM Michael Binz <michab66 at gmail.com> wrote:
>>> Hi all,
>>> I opened a proposal for an extension of the javafx.scene.Scene API to
>>> to add a stylesheet using a typed java.net.URL.
>>> Currently the Scene class offers a list of stylesheet URLs in their
>>> stringified representation accessible by Scene.getStylesheets().
>>> The problem is that in some cases an URL instance encapsulates internal
>>> state that gets lost in the conversion into its external form and back
>>> an URL instance, namely information on an URL handler. This ultimately
>>> results in a failure (IOException file not found) when the Screen class
>>> tries to load a stylesheet though code that loads the file contents using
>>> URL#openStream() on the original URL instance can read the file contents
>>> In my case the problem showed up when creating an executable jar file
>>> containing my JavaFX application (using OneJar). The application startup
>>> in this case installs a customized Classloader that implements special
>>> logic for accessing the jars contained classes, This works transparently
>>> for classes and resources, but the URLs returned by Class#getResource(
>>> ) do not survive the conversion to string and back because of the
>>> There is a workaround that caches the resource in a temporary file and
>>> passes this file's URL to the Scene's list of stylesheets, but this poses
>>> other problems.
>>> As a remark, other APIs in JavaFX use the same pattern of expecting
>>> stringified URLs like the Image() constructor and have the same problem,
>>> but offer alternative constructors accepting a stream which allows to
>>> the problem nicely.
>>> Please discuss and decide if the proposal can be added as a change
>>> for JavaFX.
>>> Best wishes,
More information about the openjfx-dev