CSS

编写 CSS
#root {
-fx-background-color: #ccc;
}
.custom {
-fx-background-color: #088;
}
.label {
-fx-text-fill: #0af;
}
.label:hover {
-fx-text-fill: #f08;
-fx-font-size: 30;
}
Java 代码加载 CSS
Scene scene = new Scene(root);
URL sampleCss = getClass().getResource("/css/sample.css");
scene.getStylesheets().add(sampleCss.toString());
FXML 添加 CSS
<HBox fx:id="root" stylesheets="/css/sample.css" spacing="10" alignment="center" prefHeight="400" prefWidth="300" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.lsdev.sample.Controller">
<Button fx:id="btn" text="%hello" styleClass="custom" />
<Label text="Label1" />
<Label text="Label2" />
</HBox>