-
CSR
-
Resolution: Unresolved
-
P4
-
None
-
binary
-
minimal
-
The compatibility risk is minimal because no existing APIs are changed. The BSS file format is changed to allow storing media queries, which means that BSS files created with an earlier version of JavaFX can't be read.
-
Java API, File or wire format
-
JDK
Summary
Add media queries to JavaFX CSS, which is a powerful feature that allows stylesheets to dynamically test certain aspects of the JavaFX scene.
Problem
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 are the mechanism with which stylesheets can test these preferences.
Solution
We add Scene.Preferences
, which contains scene-specific instances of several of the properties defined in Platform.Preferences
. The reason why we have scene preferences and don't use platform preferences directly is to allow applications to override OS preferences per scene. Consider the colorScheme
preference: most applications that offer light and dark themes also allow users to switch between them independently from the OS. The advantage of allowing Scene to override those properties is that an application can mix and match light and dark themes.
This might be useful for stylistic or compatibility reasons. For example, an application might use third-party UI components in tool windows that don't work well with a dark theme (maybe even Swing content), so these windows would use a color scheme that is different from the main window.
The Scene.Preferences
properties and their associated media queries are:
persistentScrollBars
/ -fx-prefers-persistent-scrollbars
reducedMotion
/ prefers-reduced-motion
reducedTransparency
/ prefers-reduced-transparency
reducedData
/ prefers-reduced-data
colorScheme
/ prefers-color-scheme
These properties are null-coalescing, which means that if set to null
(either with a binding, or with their setValue()
method), their value evaluates to the corresponding value of Platform.Preferences
. In this way, application developers can either set the property values directly, or leave them "unspecified", in which case the platform property value is used instead.
Specification
Add the Scene.Preferences
interface.
- csr of
-
JDK-8345348 CSS media feature queries
-
- In Progress
-