samedi 4 avril 2015

How to stretch an image so that it fits the entire screen in javafx

Relevant code



package whowantstobeamillionairetriviagame;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class WhoWantsToBeAMillionaireTriviaGame extends Application
{
@Override
public void start(Stage startingStage) throws Exception
{
Image backgroundColor = new Image("http://ift.tt/1Hy4Bhb");

BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, false);
BackgroundImage backgroundImage = new BackgroundImage(backgroundColor, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, backgroundSize);

StackPane background = new StackPane();
background.setBackground(new Background(backgroundImage));

Scene menuScene = new Scene(background);
startingStage.setScene(menuScene);
startingStage.setFullScreen(true);
startingStage.show();
}

public static void main(String[] args)
{
launch(args);
}
}


I'm asking because using repeat will cause the picture to repeat over and over the x and y axis so it can fit the whole entire screen. Using no repeat will leave a bunch of white spaces all around it. Round, Space and setting the stage to full screen doesn't help either. What can i do?


Aucun commentaire:

Enregistrer un commentaire