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

CSS media feature queries

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • javafx
    • None
    • In Review

      In JavaFX 22, we added Platform Preferences to enable applications adjust their styling to OS preferences. However, except for replacing its stylesheets entirely, there is no easy way for an application to adjust its stylesheets at runtime.

      Media queries should be added to JavaFX, which is a powerful feature that allows stylesheets to dynamically test certain aspects of the JavaFX scene. Media queries are independent of the contents of the scene graph, its styling, or any other internal aspect; they’re only dependent on "external" configuration of the scene.

      A media query is defined in a stylesheet as follows:

          .button {
              -fx-background-color: lightgray;
          }
          
          @media (prefers-color-scheme: dark) {
              .button {
                  -fx-background-color: darkgray;
              }
          }

      In this example, the button's background color will change at runtime when the preferred color scheme is changed to dark. Since a media query can contain arbitrary CSS rules, all aspects of styling can be adjusted.

            mstrauss Michael Strauß
            mstrauss Michael Strauß
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: