Reputation: 129
Why do I have to declare the class like in the following example for every circle?
Style sheet:
.circle {
-fx-fill: #fff;
}
Code:
Circle c = new Circle(50,50,25);
c.getStyleClass().add("circle");
I have watched some videos on how to use style sheets with JavaFX. In the videos they did not have to declare the class at all and the style sheet was working. When I try to use a style sheet, however, I have to declare the class for every circle I create in order for the styles to be applied.
Is that maybe a settings thing?
My IDE is NetBeans and they use it in the videos, as well.
Upvotes: 0
Views: 40
Reputation: 209330
The documentation lists the default style classes that are assigned to each node type.
As you can see, Circle
has no default style class. (Basically default style classes are only assigned to controls, not shapes, etc.) Probably the videos you mention were using node types that had default style classes assigned.
You can consider using a Type Selector, i.e.
Circle {
-fx-fill: #fff
}
instead, if you don't want to explicitly set a style class.
Upvotes: 1