I would like to get a font settings from a CSS file:
#myCustomFont
{
-fx-font-family: "Segoe UI";
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-text-fill: red;
}
and then pass it as a parameter in several methods as Font object. For this, I used the auxiliary Text object:
Text t = new Text("Some text");
t.setId("myCustomFont");
t.applyCss();
Font myFont = t.getFont();
Unfortunately font myFont is not like in the CSS file, it has remained the default. The same problem is with setting the font in the Label object created in code similarly to the above, but if Label is implemented in fxml file of my project, font myFont2 is like in CSS:
dateTimeLabel.setText("12.01.2022"); //Label from .fxml
dateTimeLabel.setId("myCustomFont");
dateTimeLabel.applyCss();
Font myFont2 = dateTimeLabel.getFont(); //OK
What am I doing wrong?