I am trying to make an image show up as the background of my scene. Whenever I run the code, it opens the window, but the background is empty. I have tried some of the solutions from here:
JavaFX How to set scene background image
and from here:
and I could not get either of them to work properly.
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class Starbase extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Starbase Command");
Pane pane = new Pane();
ImageView imageView = new ImageView(new Image("file:space.jpg"));
imageView.setFitHeight(800);
imageView.setFitWidth(800);
pane.getChildren().add(imageView);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
}
}