I have a JavaFX application. Some Tabs in a TabPane have a class "my-view", and inside there is a complex structure, featuring labels, textfields and so on. I have a CSS rule to set the font size on these sub-items like:
.my-view .label, .my-view .my-text-field-a, .my-view .my-text-field-b {
-fx-font-size: 12px;
}
I want to allow the user to press Ctrl-+ to dynamically increase text size. What I really want is to be able to dynamically adjust the "12px" in the above CSS, dynamically. However, I can't see a way to do this in JavaFX. The setStyle method only allows setting the style for the current node, not a rule as above. The new JavaFX 8 StyleableProperty interface seems to go in the wrong direction for me -- it allows code to read but not write CSS properties. I don't really want to have to find all the relevant text fields myself in the code and call setFont; CSS rules seem like the right mechanism here.
The only way I can currently think to do it is to create a new class for each font size that I might want to set (a bit like suggested here: Hot to update dynamically font size) and then set the appropriate class to set the size, e.g.
.my-view-12 .label, .my-view-12 .my-text-field-a, .my-view-12 .my-text-field-b {
-fx-font-size: 12px;
}
.my-view-14 .label, .my-view-14 .my-text-field-a, .my-view-14 .my-text-field-b {
-fx-font-size: 14px;
}
I can autogenerate the CSS (for all font sizes say 1-100), but this method just seems like an ugly hack. Are there any better ways to do this in JavaFX?