java - How to stretch an image so that it fits the entire screen in javafx -
java - 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://www.sonomare.com/darkblue_background_rot_180.jpg"); 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 cause image repeat on , on x , y axis can fit whole entire screen. using no repeat leave bunch of white spaces around it. round, space , setting stage total screen doesn't help either. can do?
you can set background size cover.
from docs
the size might defined cover = true, meaning image should stretched cover entire rendering surface of region.
the definition backgroundsize becomes
backgroundsize backgroundsize = new backgroundsize(100, 100, true, true, true, true);
java image javafx
Comments
Post a Comment