javacssjavafxjavafx-css

What's the difference between -fx-text-fill and -fx-text-inner-color in JavaFX CSS?


From the JavaFX CSS Reference Guide I know enough about the -fx-text-fill property to use it.

Working on a larger JavaFX project that has recently been updated to JavaFX 16, I came across some CSS code that uses -fx-text-inner-color to apparently achieve the exact same thing, that is changing the text color of (in my case) a TextField control.

Since I could not find any documentation on the second property, I decided to ask here.

Can someone explain the difference between those two properties, why might we need both of them, and when to prefer one over the other?


Solution

  • -fx-text-fill is a CSS property that is defined for controls with text properties (such as Labeled and its subclasses, and TextInputControl and its subclasses).

    The property, as noted in the question, is listed in the JavaFX CSS Reference Guide.

    -fx-text-inner-color is not a property, but a looked-up color (essentially a CSS color variable) that is defined in the default stylesheet modena.css. It is used as the value of the -fx-text-fill property for controls which have a background color set to -fx-control-inner-background, namely "text boxes, password boxes, lists, trees, and tables".

    Changing -fx-text-inner-color at the root level will have the effect of changing the text color on all text boxes, password boxes, lists, trees, and tables.

    Note that the default value of -fx-text-inner-color is set to a color ladder, which depends on the value of -fx-control-inner-background. Namely, when -fx-control-inner-background is dark (less than 45% intensity), it is set to -fx-light-text-color, when it is light (greater than 60% intensity, which it is by default), it is set to -fx-mid-text-color, and otherwise it is set to -fx-dark-text-color. The default values of these are white, #333, and black, respectively.

    The effect of these default settings is to get a text fill which always contrasts with the background; so if you change the value of -fx-control-inner-background the text color will adjust automatically.

    There are really two distinct approaches to defining a production-level style for an application: