JI-9056801 : Scene: Allow to add a stylesheet using a typed URL, not a stringified URL

Tom Schindl tom.schindl at bestsolution.at
Sat Sep 15 18:39:36 UTC 2018


I don't understand why something should be lost but anyways I don't
think JavaFX API is not the right place to fix a short coming of OneJar.
As Nir pointed out it is next to impossible to retrofit the JavaFX API
to URL with breaking it.


On 22.08.18 20:47, Michael Binz wrote:
> Hi all,
> I opened a proposal for an extension of the javafx.scene.Scene API to allow
> 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 into
> 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
> successfully.
> 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( name
> ) do not survive the conversion to string and back because of the described
> reason.
> 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 solve
> the problem nicely.
> Please discuss and decide if the proposal can be added as a change request
> for JavaFX.
> Best wishes,
> Michael.

Tom Schindl, CTO
BestSolution.at EDV Systemhaus GmbH
Eduard-Bodem-Gasse 5-7. A-6020 Innsbruck
Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck

More information about the openjfx-dev mailing list