I have stored the default font type and size of my application in a CSS file which I apply using the code:
label.getStyleClass().add("labelStyleClass");
However I also added the feature that if the user provides its own preference, it should override the default settings (set above) and use the user provided font size:
double userSize = readFromFile;
label.setFont(new Font(userSize));
In this case the label.setFont()
call does not set the new size given by user. When I comment out the initial CSS code, the later works.
Any workaround?
Note: cross-posted at JavaFX forum
It's by design. For architectural reasons chain of overrides for css is as follows:
Or, quoting css reference guide:
Thus, you can achieve your goal by using
setStyle()
instead of API call. Try to run next example: