Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8187572

Image URLs in default stylesheets break when default stylesheets imported into custom stylesheets

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_141"
      Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)


      A DESCRIPTION OF THE PROBLEM :
      When creating a new stylesheet for application-wide use with Application.setUserAgentStyleSheet , we want to base it on the default Modena stylesheet by using @import "com/sun/javafx/scene/control/skin/modena/modena.css"; and adding our additional styling.

      However, all URLs (for graphics) in modena.css can not be resolved anymore if we do that, because they are defined as e.g.
      .html-editor-cut {
          -fx-graphic: url("HTMLEditor-Cut.png");
      }
      So with the @import, the URLs will be resolved relative to the classpath of our custom stylesheet, not relative to modena.css . This leads to warnings because the files cannot be found:

      Sep 13, 2017 11:53:41 AM com.sun.javafx.css.StyleManager getCachedImage
      WARNING: Error loading image: file:/path/to/our/stylesheet/HTMLEditor-Cut.png


      As there is no way to add multiple application-wide stylesheets (Application.setUserAgentStyleSheet only takes a single one, adding stylesheets to Scenes is only Scene-wide and not application-wide), and StyleManager.getInstance().addUserAgentStylesheet is private API, this issue makes the only way we know to provide a custom, but Modena based stylesheet for the whole application impractical/error-prone.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a custom stylesheet that imports the default Modena stylesheet : @import "com/sun/javafx/scene/control/skin/modena/modena.css";

      Use custom stylesheet as application-wide stylesheet in an application with Application.setUserAgentStyleSheet .

      Try to display a control with a style class that contains a URL reference for a graphic, for example, show a confirmation or choice dialog.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The images referenced by the URLs should be displayed (just as if Modena had been used as the application-wide stylesheet) and there should be no warnings about the image files not being found.
      ACTUAL -
      The images referenced by the URLs are not shown and there are warnings about the image files not being found, e.g.
      Sep 13, 2017 11:53:41 AM com.sun.javafx.css.StyleManager getCachedImage
      WARNING: Error loading image: file:/path/to/our/stylesheet/dialog-confirm.png

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      We could manually override all CSS definitions containing url references from Modena.css in our custom stylesheet and use absolute paths like "/com/sun/javafx/scene/control/skin/modena/HTMLEditor-Underline.png". This seems error-prone (will break if Modena.css is changed).

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: