Programatically
For your StackPane
you can use BackgroundImage class:
BackgroundImage backgroundImage= new BackgroundImage(new Image(getClass().getResource("thinking-man.jpg").toExternalForm(),32,32,false,true),
BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,
BackgroundSize.DEFAULT);
stackPane.setBackground(new Background(backgroundImage));
For buttons: Buttons have a graphic property:
button.setGraphic(new ImageView(new Image(getClass().getResource("thinking-man.jpg").toExternalForm())));
Using CSS
If you would prefer to use stylesheets to set background images you can use:
-fx-background-image, -fx-background-repeat, -fx-background-position and -fx-background-size.
For details you can read the JavaFX CSS reference for Region class.
Using the same example with StackPane
:
stackPane.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
stackPane.getStyleClass().add("stackpane-with-background");
In application.css:
.stackpane-with-background{
-fx-background-image: url("thinking-man.jpg");
-fx-background-repeat: stretch;
-fx-background-size: 900 506;
-fx-background-position: center center;
-fx-effect: dropshadow(three-pass-box, black, 30, 0.5, 0, 0);
}
Hope this helps.