Understanding naming convention for style classes and properties

All JavaFX classes are mapped to CSS ones by converting their camel-case names to all lowercase letters with hyphens as word separators.

For example, GridPane will be called grid-pane in CSS and you can style all GridPane objects by adjusting the corresponding style class:

.grid-pane {
-fx-background-color: lightblue;
-fx-padding: 10px;
}

This hyphen approach works for properties as well. For example, knowing there is a property named minWidth, you can see that the corresponding CSS style property will be named -fx-min-width.

There is also a special .root style class which refers to any layout manager used in Scene.setRoot().

Also, you can introduce your own style classes and assign them to JavaFX elements manually:

// CSS
.blue-style {
-fx-background-color: lightblue;
}

// JavaFX
button.getStyleClass().add("blue-style");

Note that a node can have several assigned style classes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.240.244