I want to set one css file to my whole application. I read several similar topic, but I didn't find solution. This is my code:
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("../view/MainView.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(this.getClass().getResource("modena_dark.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
There is no error, just stylesheet doesn't work and app window looks standard. File "modena_dark.css" is in the same directory as file with this code.
If your .css file is in the same directory as your java class, try using:
scene.getStylesheets().add("/yourpackage/modena_dark.css");
This works for me without any problems.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.