I'm still pretty new to JavaFX, but I discovered style sheets recently and found that you can use it to set the design of your application. I wanted to see if I could change the background of my app to an image. This is my current project setup:
16copia.jpg
is what I want to set the background to.
And this is my style.css setup.
.root{
-fx-font-family: 'JetBrains Mono';
-fx-font-size: 10px;
-fx-background-image: url("16copia.jpg");
-fx-background-repeat: no-repeat;
-fx-background-size: stretch;
}
.button{
-fx-base:lightblue;
}
.label {
-fx-text-fill: lightblue;
}
In my main class, I added the style sheet to my main scene. Also tried using root.setStyle, but to no avail.
public void start(Stage stage){
stage.setTitle("Calculator App");
genMenuBar();
setFunctionality();
Scene mainScene = new Scene(root, 300, 500);
root.setBottom(calcView);
root.setCenter(displayView);
mainScene.getStylesheets().add("style.css");
stage.setScene(mainScene);
stage.show();
//root.setStyle("-fx-background-image: url('src/main/java/calculator/app/16copia.jpg');");
}
When I run the program, all of the CSS styling except for the image is applied.
Not meant to be the final look, mostly just experimenting with style sheets:
The program runs with no errors, but the bug persists. I'd prefer to stick to CSS styling if possible.