Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have one node ignore a CSS class entry

So I have the following code snipet which I want applied to 99% of my labels in my JavaFX application. However, sometimes I don't want it applied. Unfortunately whenever I try to call

myFont.setFont(Font.loadFont(etc etc);

It is unable to override the label class in the CSS file. How can this be done? Thank you!

.label
{
    -fx-font-size: 14pt;
    -fx-font-family: "Segoe UI Semibold";
}
like image 766
Hatefiend Avatar asked Mar 31 '26 16:03

Hatefiend


1 Answers

There are different ways to do it. Few of the approaches are described here :

  • Define a different style-class instead of using the default .label and use it on your 99% of labels.

Code :

mylabel.getStyleClass().add("my-label")

CSS :

.my-label {
   -fx-font-size: 14pt;
   -fx-font-family: "Segoe UI Semibold";
}
  • Remove the default label style class and set a new style class to 1% of the labels. This will remove the already present .label style class from the node. This seems to be an easier approach but if I were you, I would not go with this approach since we <3 the default styles and we want them to be applied to the respective nodes by default.

Code :

mylabel.getStyleClass().setAll("my-label");
like image 96
ItachiUchiha Avatar answered Apr 03 '26 05:04

ItachiUchiha