2015-04-04 46 views
1

相关代码如何,使其适合在JavaFX的整个屏幕

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); 
} 
} 

我这么问是因为重复使用会造成画面一遍遍在x和y轴重复因此它可以拉伸图片适合整个屏幕。不使用重复会在其周围留下一堆空白空间。 Round,Space和将舞台设置为全屏也无济于事。我能做什么?

回答

0

您可以将背景大小设置为封面。

从文档

大小可能与盖=真,这意味着图像应被拉伸以覆盖该区域的整个渲染表面来限定。

定义为BackgroundSize成为

BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, true); 
+0

谢谢主席先生,看起来好多了。 – 2015-04-04 20:42:31